Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

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. Ken Williams Feb 28 at 20:08

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://yourLogin@github.com/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.

    Any comments on importing issues and labels? Can anything other than code be imported by pull and push? Thanks. – user1225054 May 31, 2015 at 19:18 @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) – VonC Feb 6, 2017 at 14:25 @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. – VonC Dec 24, 2021 at 12:52 @mike Good point, thank you. I have included your comment in the answer for more visibility. – VonC May 12, 2022 at 22:15 @FellipeTavares I agree: importing a project (repo+MR+issues+wiki+...) is trickier, as described here. – VonC Jan 18 at 17:51

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

    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. – abalter Jun 29, 2017 at 5:03 Just a quick note for anyone else using the import option. I had to disable MFA on GitLab for this to work. – D-Day Mar 11, 2018 at 19:09 The imported repository does not necessarily have to be public now, as github has made adding private repositories free. – Shrey Garg Oct 29, 2019 at 8:03 @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. – Sajib Acharya Oct 20, 2020 at 9:01 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 sophisticated – gaurav5430 Jun 1, 2021 at 17:32

    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:

    git@github.com: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 = git@github.com: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.

    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. – uch Aug 16, 2021 at 13:14

    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.

    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
                    This is the way easiest when we need to push from Local (cloned before from GitLab) to GitHub, tks bro!!!
    – Nghien Nghien
                    Nov 4, 2022 at 14:43
                    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.)
    – Michael M.
                    Jul 23, 2021 at 17:30
    

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

    Thanks

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

  • 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

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

    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.

    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.

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.

  •