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.
- 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.
There should be an entry under Mirrored Repositories
- Copy the SSH public key.
Back on Github, go to the repositories settings.
- Add the key as a deploy key.
- Be sure to check the allow write access.
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.