Reputation: 2983
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:
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. :)
Upvotes: 82
Views: 52516
Reputation: 457
If there are too many repos on your gitlab, it's too difficult to migrate or mirror those repos.
I was in the same situation before, to solve this, I wrote an easy tool to mirror all you visible repos between gitlab and github. For example, it will mirror-clone all you visible repos on gitlab, create repos on your github account, and mirror-push them.
Gitee is not supported now, you could see tests.go to reliaze how to use it.
https://github.com/kom0055/git-mirror
I'm writing a more specific readme.
Upvotes: 2
Reputation: 91
Post Aug 13, 2021 Use of just username/password for mirroring repo from GitLab to GitHub will fail because we need to use a personal access token (PAT) to do this.
Step 1: Create a PAT from GitHub:
You should also be able to see your personal access token. Make sure to copy it as we will need it in the following step(s).
Step 2: From GitLab, Go to repo you wish to mirror:
Upvotes: 6
Reputation: 840
If you prefer SSH connection over HTTPS connection for GitLab to GitHub mirroring:
[email protected]:yourusername/yourrepositoryname.git
)ssh://[email protected]/yourusername/yourrepositoryname.git
Upvotes: 19
Reputation: 17919
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://[email protected]/yourUserNameInGitHub/yourRepoName.git
In the password field, you have to use a Personal Access Token (as GitHub has deprecated password access now), which you can generate here: https://github.com/settings/tokens (don't forget to enable the "repo" and "workflow" permissions when generating it)
Upvotes: 87
Reputation: 19938
Another options is to add an additional URL to the origin
:
git remote set-url --add origin [email protected]:<USERNAME>/<PROJECTNAME>.git
When you push to origin it will push to both the original origin (gitlab) and the one added above (github).
Upvotes: 25
Reputation: 6947
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:
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
Upvotes: 15