[git] Transfer git repositories from GitLab to GitHub - can we, how to and pitfalls (if any)?

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

This question is related to git github transfer gitlab repository

The answer is


You can transfer those (simply by adding a remote to a GitHub repo and by 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 loose the access control (teams defined in GitLab with specific access rights on your repo)

If you facing 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".


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


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.


I had the opposite problem and finally had to create my own bash shell script for the company to migrate the hundred of repos from Github to Gitlab due to a change in the company policy.
The script use the Gitlab API to remotely create a repo, and push the Github repo into it. There is no README.md file yet, but the sh is well documented.
The same thing can be done opposite way I imagine. Hope this could help.
https://github.com/mahmalsami/migrate-github-gitlab/blob/master/migrate.sh


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

Thanks


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


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


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to github

Does the target directory for a git clone have to match the repo name? Issue in installing php7.2-mcrypt How can I switch to another branch in git? How to draw checkbox or tick mark in GitHub Markdown table? How to add a new project to Github using VS Code git clone error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054 How to add empty spaces into MD markdown readme on GitHub? key_load_public: invalid format git - remote add origin vs remote set-url origin Cloning specific branch

Examples related to transfer

Transfer git repositories from GitLab to GitHub - can we, how to and pitfalls (if any)? How to transfer paid android apps from one google account to another google account Why when I transfer a file through SFTP, it takes longer than FTP?

Examples related to gitlab

GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? HTTP Basic: Access denied fatal: Authentication failed Getting permission denied (public key) on gitlab Delete commit on gitlab error: RPC failed; curl transfer closed with outstanding read data remaining ssh : Permission denied (publickey,gssapi-with-mic) Fix GitLab error: "you are not allowed to push code to protected branches on this project"? Change Default branch in gitlab How can I clone a private GitLab repository?

Examples related to repository

Kubernetes Pod fails with CrashLoopBackOff Project vs Repository in GitHub How to manually deploy artifacts in Nexus Repository Manager OSS 3 How to return a custom object from a Spring Data JPA GROUP BY query How do I force Maven to use my local repository rather than going out to remote repos to retrieve artifacts? How do I rename both a Git local and remote branch name? Can't Autowire @Repository annotated interface in Spring Boot How should I deal with "package 'xxx' is not available (for R version x.y.z)" warning? git repo says it's up-to-date after pull but files are not updated Transfer git repositories from GitLab to GitHub - can we, how to and pitfalls (if any)?