Home Mirror a Gitlab repository to Github
Post
Cancel

Mirror a Gitlab repository to Github

Mirror a Gitlab repository to Github

Git repository mirrors can be useful to create a real-time copy of a repository for backup purposes, or as a transitional step when moving from one git platform to another. In this post we will walk through creating a mirror from a Gitlab repository to create a Github repository.


To start off create a new empty repository in Github. Do not add a readme or any other files.

image

  • Copy the SSH clone URL - [email protected]:Sarlaac/sandbox-mirror.git
  • Update the URL to add ssh:// and change the colon after github.com

ssh://[email protected]/Sarlaac/sandbox-mirror.git


Now let’s logon to Gitlab and go to the repository you want to mirror.

  • In the repository, go to Settings > Repository > Mirroring repositories
  • Enter the URL we created earlier.
  • Click on detect host keys
  • Switch from password to SSH public key
  • Click on the Mirror repository button.

image

There should be an entry under Mirrored Repositories

  • Copy the SSH public key.

image


Back on Github, go to the repositories settings.

  • Add the key as a deploy key.
  • Be sure to check the allow write access.

image

That’s it! Test the setup by committing a change on the Gitlab repository and go look for it to be mirrored to the Github repository. If you are interested in how this mirror can be used to restore a corrupt or lost repository I have a post for that now.

This post is licensed under CC BY 4.0 by the author.