Create a gist now

Instantly share code, notes, and snippets.

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 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 commented Dec 21, 2016

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

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

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

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!

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

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