Transfer git repositories from GitLab to GitHub - can we, how to and pitfalls (if any)?
Solution 1
You can transfer those (simply by adding a remote to a GitHub repo and pushing them)
- create an empty repo on GitHub
git remote add github https://[email protected]/yourLogin/yourRepoName.git
git push --mirror github
The history will be the same.
But you will lose the access control (teams defined in GitLab with specific access rights on your repo)
If you face any issue with the https URL of the GitHub repo:
The requested URL returned an error: 403
All you need to do is to enter your GitHub password, but the OP suggests:
Then you might need to push it the ssh way. You can read more on how to do it here.
See "Pushing to Git returning Error Code 403 fatal: HTTP request failed".
Note that mike also adds in the comments:
GitLab can also be set to push mirror to downstream repositories, and there are specific instructions for push mirroring to GitHub.
This can use a GitHub Personal Access Token and also be set to periodically push.
You might use this option to share on GitHub, but keep your main development activity in your GitLab instance.
Solution 2
This is very easy by import repository feature
Login to github.com
,
Side of profile picture you will find +
button click on that then there will be option to import repository
.
you will find page like this.
Your old repository’s clone URL is required which is gitlab repo url in your case.
then select Owner and then type name for this repo and click to begin import button.
Solution 3
If you want to migrate the repo including the wiki and all issues and milestones, you can use node-gitlab-2-github and GitLab to GitHub migration
Solution 4
You can use the following commands:
cd existing_repository
git remote rename origin old-origin
git remote add origin <yourRepository.git>
git push -u origin --all
git push -u origin --tags
If an error occurs, you can try to force the push using the -f
command, type like this:
git push -u -f origin --all
git push -u -f origin --tags
This would be the path recommended by GitLab to import an existing repository on GitHub, however, if you change the <yourRepository.git>
link to the repository link on GitHub it is possible to go the other way, transferring from GitLab to GitHub. In practice, you create a new origin and force a push of everything.
Solution 5
For anyone still looking for a simpler method to transfer repos from Gitlab to Github while preserving all history.
Step 1. Login to Github, create a private repo with the exact same name as the repo you would like to transfer.
Step 2. Under "push an existing repository from the command" copy the link of the new repo, it will look something like this:
[email protected]:your-name/name-of-repo.git
Step 3. Open up your local project and look for the folder .git
typically this will be a hidden folder. Inside the .git
folder open up config
.
The config file will contain something like:
[remote "origin"]
url = [email protected]:your-name/name-of-repo.git
fetch = +refs/heads/:refs/remotes/origin/
Under [remote "origin"]
, change the URL to the one that you copied on Github.
Step 4. Open your project folder in the terminal and run: git push --all
. This will push your code to Github as well as all the commit history.
Step 5. To make sure everything is working as expected, make changes, commit, push and new commits should appear on the newly created Github repo.
Step 6. As a last step, you can now archive your Gitlab repo or set it to read only.
Related videos on Youtube
boddhisattva
Mohnish is: A human being driven by values & a person who cares about people & his work | Programmer (9.5+ years) with primary experience using Ruby(7+ years) | Experience in Elixir(elementary) | An open source contributor | A blogger | A believer in Vasudhaiva Kutumbakam Some of his open source project contributions: Codebar Planner(contributions present here) - The project that powers https://codebar.io/ Ruby Hexpm Elixir Lang Website - including adding a Debugging chapter in collaboration with Jose Valim Some of his side projects include: [Ruby] A sales tax problem here [Rails] An Activities collator app built using Rails here Some of the Ruby articles that he's written include - How to Setup RSpec, Factory Bot and Spring for a Rails 5 Engine Learnings from facilitating a Ruby meetup where people solved an Exercism kata via Pair programming Guest blogs The journey of solving an Elixir exercise on Exercism and how that led me to look beyond the impostor syndrome His experience with working in a Distributed Team towards building a Javascript project He blogged on the CodeNewbie site about the experience of building a hangman game Some of his speaking opportunities include Code Beam SF 2018 on Learning Elixir Better through Collaboration & Giving Back 5 Random Ruby Tips(covering some really useful Pry features) at a Singapore Ruby Group meetup I believe in giving back & if there's a way I can respond to your questions on anything related to software or other areas, I'll try my best to get back time permitting. My email - [email protected]. Have a fulfilling day ahead! :)
Updated on July 08, 2022Comments
-
boddhisattva almost 2 years
Can one transfer repositories from GitLab to GitHub if the need be. If so, how exactly can I go about doing the same?
Also, are there any pitfalls in doing so or precautionary measures that I need to keep in mind before doing so given that I may decide to eventually move them to GitHub (as it has more features at the moment that I might find handy for my project).
-
boddhisattva about 10 yearsThanks Von - your answer did the trick for me.I've just added a bit to your answer regarding the exact git remote add cmd and pushing things the ssh way if the need be. Hope that's okay.
-
VonC about 10 years@boddhisattva It is ok, but I see your edit was rejected. I have added it back in the answer myself.
-
Admin almost 9 yearsAny comments on importing issues and labels? Can anything other than code be imported by pull and push? Thanks.
-
VonC almost 9 years@YakovK I am not aware of an automatic process taking into account PR and issues. At least, PR in GitHub are branches (see stackoverflow.com/a/30542987/6309), so that could be imported.
-
Santiago Suárez over 8 years@VonC where would you need to enter your GitHub password after the 403 error? I'm trying to migrate from gitlab to github and I'm finding it to be a pain
-
Santiago Suárez over 8 years@VonC I already answered my own question, upgraded my git version and it automatically prompted for my credentials when following your answer, Thanks!
-
VonC over 8 years@SantiagoSuárez Great! Sorry for the late answer. I wasn't available.
-
kiki over 7 yearsThis works well, however it only pushed tags and the master. Any idea how I can get the branches, too?
-
VonC over 7 years@kiki it will push all local branches, but if your local repo is itself a clone, it will have only master as its default local checked out branch. You must first create the other local branches after their repsective remote tracking branches, before using
push --mirror
. stackoverflow.com/a/18911322/6309. See also the alternative mentioned at stackoverflow.com/a/24099141/6309 (last sentence) -
abalter almost 7 yearsThat is super convenient that GitHub has added that. However, it won't work if it is an internal GitLab behind a firewall, which represents a large use case for GitLab.
-
D-Day about 6 yearsJust a quick note for anyone else using the import option. I had to disable MFA on GitLab for this to work.
-
jtlz2 about 5 yearsgit: 'credential-manager' is not a git command. See 'git --help'. !?
-
VonC about 5 years@jtlz2 Check your
%PATH%
. Mine includesc:\path\to Git\bin;c:\path\to Git\cmd;c:\path\to Git\usr\bin;c:\path\to Git\mingw64\bin
. With that, credential-manager is correctly interpreted. -
LnxSlck almost 5 yearsThis works fine. Much better than the accepted answer
-
questionasker almost 5 yearsHow if i want to import branch ?
-
Shrey Garg over 4 yearsThe imported repository does not necessarily have to be public now, as github has made adding private repositories free.
-
Akron over 4 yearsDoes this create a new repo on github or would you have to do that via web browser first?
-
VonC over 4 years@Akron You have to create a new empty GitHub repository on the web first, then you can add locally the remote URL of the GitHub repository you just created, and push to it.
-
Hector over 3 yearsIn case that Gitlab repository is private, I had to create previously a token in Gitlab with read only access, then I can use these credentials to login in Github when the import step ask me
-
Sajib Acharya over 3 years@D-Day you do not need to disable MFA. I faced the same problem, all you need to do is create a personal access token on GitLab and use that as your password while importing to GitHub.
-
Leon Matota over 3 yearsfor further reading, look at this article android.jlelse.eu/…
-
gaurav5430 almost 3 yearsFYI node-gitlab-2-github can migrate issues, PRs, labels and milestones and is a little more feature rich, the other one can migrate issues, milestones and wikis , but is a little less sophisticated
-
gaurav5430 almost 3 yearsthis only transfers the repo itself, no issues, PRs, labels, milestones or anything else. Still easier than doing it from gitlab to local to github
-
Michael M. almost 3 yearsAlmost certainly you want a deploy token, not a deploy key. (You need a username/password to give to GitHub, and you can't upload private ssh keys there.)
-
uch over 2 yearsif this method does not have "pitfalls", it is a nice way to push to gitlab and github at the same time. You should just type relevant urls: one under another.
-
Alex over 2 yearsNo issues or tags transfered .. IMO insuficcient, I would have expected more
-
Nemra Khalil over 2 yearsmuch better! but will this transfer the repos history of commits too?
-
Michael Delgado over 2 years@NemraKhalil yes it transfers the git history/branches/etc, but not the additional gitlab content (permissions, issues, tags, etc)
-
Reggie Escobar over 2 yearsDoes this mean that when I want to push new changes I would have to do git push github [branch_name] instead of using origin?
-
VonC over 2 years@ReggieEscobar No, you can delete
origin,
(git remote remove origin
) renamegithub
origin
asorigin
(git remote rename origin github
), and go ongit push
(toorigin
, which is now GitHub): the transfer from GitLab to GitHub is complete. -
MehranTM over 2 yearsI tried this method to import from bitbucket but it did not find my repo even with the correct credentials. I tried both email and username in separate attempts
-
nsof about 2 yearsTo complete the action you might want to make sure your local repository points to the new remote by running the following command
git remote set-url origin https://github.com/your-repository.git
-
mike about 2 yearsGitLab can also be set to push mirror to downstream repositories, and there are specific instructions for push miroring to GitHub. This can use a GitHub Personal Access Token and also be set to periodically push. You might use this option to share on GitHub, but keep your main development activity in your GitLab instance
-
VonC about 2 years@mike Good point, thank you. I have included your comment in the answer for more visibility.