Skip to content

Instantly share code, notes, and snippets.

@mariozig
Last active December 22, 2022 08:32
Star You must be signed in to star a gist
Save mariozig/bd3bb50593e6d911946b to your computer and use it in GitHub Desktop.
Migrate repo from GitLab to GitHub Full blog post @ http://ruby.zigzo.com/2015/03/23/moving-from-gitlab-to-github/
# Assume we are in your home directory
cd ~/
# Clone the repo from GitLab using the `--mirror` option
$ git clone --mirror git@your-gitlab-site.com:mario/my-repo.git
# Change into newly created repo directory
$ cd ~/my-repo.git
# Push to GitHub using the `--mirror` option. The `--no-verify` option skips any hooks.
$ git push --no-verify --mirror git@github.com:mario/my-repo.git
# Set push URL to the mirror location
$ git remote set-url --push origin git@github.com:mario/my-repo.git
# To periodically update the repo on GitHub with what you have in GitLab
git fetch -p origin
git push --no-verify --mirror
@lotka
Copy link

lotka commented Dec 5, 2016

After running the push command I get this:

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

@skokcha
Copy link

skokcha commented Dec 21, 2016

Any answer to the above lotka error. I am getting the same thing. Thank you in advance.

@scrumit
Copy link

scrumit commented Dec 28, 2016

I'm assuming you do mean the push command so it's github that is complaining about public key failure.

Have you got one key pair for both sites, or two different pairs?

You might want to check your key work before you run this script, this doc page includes a link to testing your public key is installed correctly.

@tahnik
Copy link

tahnik commented Feb 9, 2017

Use HTTPS urls instead of SSH url if you are having the error about publickey. That should do the same thing.

So instead of git@your-gitlab-site.com:mario/my-repo.git use https://your-gitlab-site.com:mario/my-repo.git

@dreamyguy
Copy link

On Github there's a menu featured as a + icon besides your profile picture. Click on it and you'll fine an option called Import repository. Enter the URL of your Gitlab project there and... smile! 🥇

@delatbabel
Copy link

This is working well for me in reverse -- importing github to gitlab. Using the other methods didn't work because:

  • The repository is private, in an organisation.
  • The organisation permissions don't allow access via an API key.
  • I don't want to integrate github with gitlab at this stage because the gitlab instance is entirely private.

Thanks for the script!

@chenxeed
Copy link

Using HTTPS urls works for me, thanks @tahnik and @mariozig !

@fenjuan
Copy link

fenjuan commented Mar 13, 2018

Thanks very much. Did all the first part of mirroring, and successfully moved my gitlab project to github. But afterwards, the new local fold just looks wired. Therefore, I cloned the project from github to a new local folder

@panmona
Copy link

panmona commented Apr 14, 2018

Searching for an automatic way to migrate my GitLab issues.

@sreepriyaks
Copy link

I had the below issue when using gitlab and github from the same computer(windows).
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

and the below steps solved the issue.

  1. create separate ssh keys for both accounts and keep it in different folders (.ssh for one and .ssh_github for the other)
  2. create an ssh config file under c:/Users/yourname/.ssh
  3. add a host entry for both gitlab and github in the ssh config file. sample below:
    Host github
    HostName github.com
    User git
    IdentityFile C:\Users\sreepriya.sreekumar.ssh_github\gitkey
    Host gitlab
    HostName gilab.com
    User git
    IdentityFile ~/.ssh/gitlab
  4. Make sure the proper keys are added to both gitlab and github
  5. open gitbash
  6. run 'eval $(ssh-agent -s)' to start the ssh agent
  7. run 'ssh-add ~/.ssh_github/gitkey' --- make sure the path is to the identity file you have given on the ssh config file, run this command for both keys. the command will prompt for the password for the key
  8. check if the connection established successfully by running these commands
    ssh -T git@gitlab.com
    ssh -T git@github.com

Ideally this should succeed

@mtshikomba
Copy link

Use HTTPS urls instead of SSH url if you are having the error about publickey. That should do the same thing.

So instead of git@your-gitlab-site.com:mario/my-repo.git use https://your-gitlab-site.com:mario/my-repo.git

Yes, this works perfect!

@grandchild
Copy link

Anyone finding this in 2020+, there is a very convenient import method from Gitlab now as well:
Click [+] in the Gitlab header > "New project" > Tab "Import project" > Select "Gitlab"

After authorization on GitHub you'll be taken to https://gitlab.com/import/github/status for easy import management.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment