Skip to content

Instantly share code, notes, and snippets.

@mariozig
Last active December 22, 2022 08:32
Show Gist options
  • Save mariozig/bd3bb50593e6d911946b to your computer and use it in GitHub Desktop.
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
@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