Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Show comment
Hide comment
@lotka

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

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

This comment has been minimized.

Show comment
Hide comment
@skokcha

skokcha Dec 21, 2016

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

skokcha commented Dec 21, 2016

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

@scrumit

This comment has been minimized.

Show comment
Hide comment
@scrumit

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

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

This comment has been minimized.

Show comment
Hide comment
@tahnik

tahnik 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

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

This comment has been minimized.

Show comment
Hide comment
@dreamyguy

dreamyguy Mar 4, 2017

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! 🥇

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

This comment has been minimized.

Show comment
Hide comment
@delatbabel

delatbabel Mar 15, 2017

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!

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

This comment has been minimized.

Show comment
Hide comment
@chenxeed

chenxeed Jul 16, 2017

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

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

@fenjuan

This comment has been minimized.

Show comment
Hide comment
@fenjuan

fenjuan 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

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

@maracuja-juice

This comment has been minimized.

Show comment
Hide comment
@maracuja-juice

maracuja-juice Apr 14, 2018

Searching for an automatic way to migrate my GitLab issues.

Searching for an automatic way to migrate my GitLab issues.

@sreepriyaks

This comment has been minimized.

Show comment
Hide comment
@sreepriyaks

sreepriyaks Apr 18, 2018

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

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

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