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
- In GitLab, Go to
Settings > Repository
- Expand the
Mirroring repositories
section - Enter
ssh://
followed by the GitHub repository SSH URL - Replace the
:
with/
aftergit@github.com
in the SSH URL - Either get the host keys and enter them manually by selecting
Input host keys manually
or click theDetect host keys
button - Switch the Auth to
SSH public key
- Click
Mirror repository
- Copy the SSH public key by clicking the Clipboard icon on the added mirrored repositories row
- Open the repository to mirror to on GitHub
- Go to
Settings > Deploy keys
- Click
Add deploy key
- Give it a title such as
GitLab
and paste the copied key from GitLab into theKey
field - Check the
Allow write access
checkbox (required for GitLab to be able to push changes to GitHub) - 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.