Transfer git repositories from GitLab to GitHub - can we, how to and pitfalls (if any)?
Asked Answered
T

13

360

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).

Tenney answered 8/3, 2014 at 6:13 Comment(1)
Readers: there are two types of answers below - those that import just the Git repository itself (with history), and those that also attempt to import other things like Merge/Pull Requests, Issues, etc. The methods that import just the repository files & history are all doing the same thing under the hood, just using different procedures. Methods doing the latter (currently just one answer by @1u-) will give you a more complete import.Blanton
I
387

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.


tswaehn suggests in the comments the tool piceaTech/node-gitlab-2-github

It is possible to migrate issues, labels, ... with this tool github.com/piceaTech/node-gitlab-2-github: I tested it, not bad.
But had issues when transferring attachments of the issues itself.
Still worth a try, maybe.

Frotz notes in the comments that:

I've since discovered that there's a wait option available to use in the user-editable settings.ts file that's not documented anywhere.
I discovered it while implementing my own quick-and-dirty delay, which did work in stopping the "Abuse detected" slowdowns


Does this mean that when I want to push new changes I would have to do git push github [branch_name] instead of using origin?

No, you can:

  • delete origin, (git remote remove origin),
  • rename github remote as origin (git remote rename github origin), and
  • go on git push (to origin, which is now GitHub): the transfer from GitLab to GitHub is complete.
Igenia answered 8/3, 2014 at 6:32 Comment(28)
Thanks 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.Tenney
@Tenney It is ok, but I see your edit was rejected. I have added it back in the answer myself.Igenia
Any comments on importing issues and labels? Can anything other than code be imported by pull and push? Thanks.Libertarian
@YakovK I am not aware of an automatic process taking into account PR and issues. At least, PR in GitHub are branches (see https://mcmap.net/q/89412/-what-are-the-nameless-heads-and-how-do-they-occur-when-i-configure-to-pull-from-in-git), so that could be imported.Igenia
@Igenia 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 painMauriac
@Igenia I already answered my own question, upgraded my git version and it automatically prompted for my credentials when following your answer, Thanks!Mauriac
@SantiagoSuárez Great! Sorry for the late answer. I wasn't available.Igenia
This works well, however it only pushed tags and the master. Any idea how I can get the branches, too?Aforementioned
@Aforementioned 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. https://mcmap.net/q/12768/-git-pull-all-branches-from-a-remote-repository. See also the alternative mentioned at https://mcmap.net/q/89413/-how-should-i-move-a-hosted-git-repo-to-a-new-host (last sentence)Igenia
git: 'credential-manager' is not a git command. See 'git --help'. !?Tamelatameless
@Tamelatameless Check your %PATH%. Mine includes c:\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.Igenia
Does this create a new repo on github or would you have to do that via web browser first?Contagious
@Contagious 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.Igenia
Does this mean that when I want to push new changes I would have to do git push github [branch_name] instead of using origin?Bricole
@ReggieEscobar No, you can delete origin, (git remote remove origin) rename github origin as origin (git remote rename origin github), and go on git push (to origin, which is now GitHub): the transfer from GitLab to GitHub is complete.Igenia
GitLab 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 instanceHeroine
@Heroine Good point, thank you. I have included your comment in the answer for more visibility.Igenia
Thank you but this is not importing a project. It's how to import a repository.Overtone
@FellipeTavares I agree: importing a project (repo+MR+issues+wiki+...) is trickier, as described here.Igenia
just adding for reference, additionally it is possible to migrate issues, labels, ... with this tool github.com/piceaTech/node-gitlab-2-github I tested it, not bad. but had issues when transfering attachements of the issues itself. still worth a try maybe.Denver
Have any of you used node-gitlab-2-github lately? It quickly slows down and stalls with API calls-per-hour limits. I tried to do an import of a relatively small repository and after an hour it was still stalled.Hinman
@Hinman I have not. You might need to comment again, using @tswaehn, if you want him to be notified.Igenia
@Denver when did you last use node-gitlab-2-github? It now runs into "Abuse detected" slowdowns, which has a side effect of disabling the user's ability to do things like file issues or add comments to them. There are probably others. I came up with a quick-and-dirty delay of ten seconds for each trip around the loop for migrating issues, but I'm pretty sure something else is breaking too because pull requests aren't transferring correctly.Hinman
@Igenia the command to rename the remote link should be git remote rename github origin (not git remote rename origin github)Cordova
@Cordova Good catch, thank you for this feedback. I have included that part of the comments in the answer for more visibility, with your fix.Igenia
@Hinman - I did use it like march 2023Denver
@Denver - I've since discovered that there's a wait option available to use in the user-editable settings.ts file that's not documented anywhere. I discovered it while implementing my own quick-and-dirty delay, which did work in stopping the `"Abuse detected" slowdowns.Hinman
@Hinman Thank you for your feedback. I have included your comment in the answer for more visibility.Igenia
C
305

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:

enter image description here

You will find a page like this:

enter image description here

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.

Chenab answered 25/2, 2017 at 8:36 Comment(13)
That 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.Shainashaine
Just a quick note for anyone else using the import option. I had to disable MFA on GitLab for this to work.Obsolete
This works fine. Much better than the accepted answerWalther
How if i want to import branch ?Louise
The imported repository does not necessarily have to be public now, as github has made adding private repositories free.Such
In 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 mePyroelectricity
@Obsolete 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.Pedate
this only transfers the repo itself, no issues, PRs, labels, milestones or anything else. Still easier than doing it from gitlab to local to githubInfrangible
No issues or tags transfered .. IMO insuficcient, I would have expected moreManly
much better! but will this transfer the repos history of commits too?Saintly
@NemraKhalil yes it transfers the git history/branches/etc, but not the additional gitlab content (permissions, issues, tags, etc)Goebbels
I 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 attemptsEse
To 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.gitBindweed
L
31

If you want to migrate the repo including the wiki and all issues and milestones, you can use node-gitlab-2-github or GitLab to GitHub migration

Levon answered 29/1, 2019 at 11:46 Comment(2)
FYI 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 sophisticatedInfrangible
Can it be used for a bulk import? (ie, without creating manually repos on gh?)Affaire
S
8

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.

Subsolar answered 19/11, 2020 at 13:7 Comment(2)
for further reading, look at this article android.jlelse.eu/…Subsolar
if 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.Pearson
S
6

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.

Scythia answered 24/6, 2021 at 13:22 Comment(0)
S
3

If you have MFA enabled on GitLab you should go to Repository Settings/Repository ->Deploy Keys and create one, then use it as login while importing repo on GitHub

Sarrusophone answered 18/2, 2019 at 9:7 Comment(1)
Almost 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.)Soakage
C
3

You can simply transfer your GitLab project to GitHub with included histories and commits following these 2 steps:

  1. Click setting on the right-hand side of your Github profile and select import repository. Then on the old repository URL paste the Gitlab repository link you want to transfer. Follow the attached screenshot Steps to import git repository

  2. Click on import then wait a minutes after verifying login credentials, Finally you're done. Check your GitHub Repository to see the changes.

Crosslegged answered 4/5, 2021 at 0:15 Comment(0)
R
3

One simple solution can be to add one more remote URL to your local repository.

Steps:

git remote add <name> <URL>
git push name 

Example:

git remote add github_origin https://github.com/...
git push github_origin
Regain answered 25/7, 2021 at 8:2 Comment(1)
This is the way easiest when we need to push from Local (cloned before from GitLab) to GitHub, tks bro!!!Pauiie
B
2

With default Github repository import it is possible, but just make sure the two factor authentication is not enabled in Gitlab.

Thanks

Brilliance answered 26/1, 2021 at 20:38 Comment(1)
Depends entirely on what method you're using, some of them work just fine with 2FA.Blanton
F
0

Be sure that you do not have MFA enabled on your GitLab's user account, otherwise it won't work. If you have MFA enabled (as it should be), disable it temporarly until you perform the import, and re-enable it again.

Fosse answered 29/9, 2022 at 16:51 Comment(0)
P
0

Here are the steps I have followed to import my repository from Gitlab into GitHub:

  1. First, you need to change the access type of your GitLab project to public. Otherwise, you will have this error: No source repositories were detected at https://gitlab.com/yourrepository.git. Please check the URL and try again.

  2. Go to your GitHub repository dashboard and Import repository enter image description here

  3. Provide your GitLab project repository URL for cloning. Also, add name and access type for your project enter image description here

  4. You will have then a form for your username and password:

  • Use your GitLab username for the username field
  • Generate a personal access token and use it as password. Here is the link how to do it. enter image description here
Pyroconductivity answered 2/2 at 19:45 Comment(0)
F
0

I migrated our repos from GitLab Community Edition 11.1.4 to GitHub by following the steps below. It kept the commit history and tags intact. Did it using command line/git bash because our GitLab isn't accessible from the Internet.

  1. Create a new repository on GitHub. You'll import your external Git repository to this new repository.

  2. On the command line, make a "bare" clone of the external repository using the external clone URL. This creates a full copy of the data, but without a working directory for editing files, and ensures a clean, fresh export of all the old data.

   $ git clone --bare https://external-host.com/EXTUSER/REPO.git
   # Makes a bare clone of the external repository in a local directory
  1. Push the locally cloned repository to GitHub using the "mirror" option, which ensures that all references, such as branches and tags, are copied to the imported repository.
   $ cd REPO.git
   $ git push --mirror https://github.com/USER/REPO.git
   # Pushes the mirror to the new repository on GitHub.com
  1. Remove the temporary local repository.
   cd ..
   rm -rf REPO.git

Got the above steps from GitHub Docs.

Figured answered 23/3 at 6:31 Comment(0)
L
-1

You can import repositories from gitlab into github use user interface (UI) with following instructions:

-> Firstly login in gitlab

-> Then copy the link of a project in gitlab

-> Then Goto github and sign in

-> Press (+) from right side of the github interface

-> Then click on the import repository

-> Then Paste the link in "Your old repository’s clone URL" in field

-> Then right the reporitory name

-> Then select private/public

-> Then press "Begin Import" button

It will import all the files with commit of your gitlab project.

After completing the project it will show

" Importing complete! Your new repository "link" is ready.

Finally your project is imported.

Loppy answered 22/5, 2022 at 19:11 Comment(1)
All this does is import the stuff tracked by Git. It does nothing to import issues, pull-requests, comments, milestones, or anything else like that.Hinman

© 2022 - 2024 — McMap. All rights reserved.