问题
I have been using a private Gitlab instance to hold all my code. But since most of the staff that work with me now have a Github account, i would really like to get moving and mirror my Gitlab repo to Github.
My situation:
- a server running Gitlab (Omnibus)
- a Github account for which I'll create an organization for where me and my staff can be organized together.
I know that there is the --mirror
switch in git, but I am not really sure how this is ment to work. Documentation I found online was very wonky... So it would be nice if someone could help me out. :)
回答1:
This previous StackOverflow question addresses how to move your repository from another service over to GitHub, the first answer there addresses how to do it via command line, and the second and third are more user friendly ways, which unfortunately will not work for you if your GitLab instance is on your local server (which seems to be your case).
You can however 'import' your repository from the command line to GitHub as explained by GitHub docs, this is the suggested way as GitHub offers this as an alternative to using their GitHub Importer tool (which is highlighted in that previous SO question)
A run down of steps as taken from the documentation:
- Create a new repository you want to push to in GitHub.
Make a local bare clone from your GitLab server:
git clone --bare https://githost.org/extuser/repo.git
A bare clone is an exact duplicate, without a working directory for editing files, so it's a clean export.
Change into that directory and then push it with the
--mirror
flag. The mirror flag ensures that references (branches/tags) are copied to GitHub.cd *repo.git*
git push --mirror https://github.com/ghuser/repo.git
Finally remove the local repository you made.
cd ..
rm -rf repo.git
回答2:
GitLab has now an option to do this from the UI, go to the Settings->Repository of your repo:
https://gitlab.com/yourUserNameInGitLab/yourRepoName/settings/repository
Then find the option "Mirror a repository" and click on expand. What you want to do is choose the "Push" mirror direction and fill this URL:
https://yourUserNameInGitHub@github.com/yourUserNameInGitHub/yourRepoName.git
回答3:
Another options is to add an additional URL to the origin
:
git remote set-url --add origin git@github.com:<USERNAME>/<PROJECTNAME>.git
When you push to origin it will push to both the original origin (gitlab) and the one added above (github).
来源:https://stackoverflow.com/questions/30268549/mirroring-from-gitlab-to-github