Functional BytesFunctional Bytes

Mirroring a GitLab Repository to GitHub


We run an internal GitLab server for our projects - this is mainly to keep our cloud CI/CD costs down but it also has the added benefit of providing an easy integration with our internal k8s deployments.

Sometimes it can also be beneficial to have some repositories mirrored to GitHub (e.g. for offsite backups, cloud integrated deploys without internal access, etc.). GitLab makes this fairly easy, as it can be setup to mirror changes on each push.

How To

  1. In GitLab, Go to Settings > Repository
  2. Expand the Mirroring repositories section
  3. Enter ssh:// followed by the GitHub repository SSH URL
  4. Replace the : with / after git@github.com in the SSH URL
  5. Either get the host keys and enter them manually by selecting Input host keys manually or click the Detect host keys button
  6. Switch the Auth to SSH public key
  7. Click Mirror repository
  8. Copy the SSH public key by clicking the Clipboard icon on the added mirrored repositories row
  9. Open the repository to mirror to on GitHub
  10. Go to Settings > Deploy keys
  11. Click Add deploy key
  12. Give it a title such as GitLab and paste the copied key from GitLab into the Key field
  13. Check the Allow write access checkbox (required for GitLab to be able to push changes to GitHub)
  14. Click Add key

Mirroring should now be running. All changes will be pushed to GitHub when the next commit is pushed to GitLab or when the refresh button is clicked on the Mirrored repositories row in GitLab.

References