Mirroring a Git Repository
I use Git for backing up purposes as well as for its awesome version control. I use Git for personal projects and I use Git for school projects. I have several repositories across several Git hosts. My main one is at Gitlab. For school I cannot use that one, as school requires me to use theirs. As I don't want to host everything I make for school on a host that I won't have access to anymore after I'm done with school, I will want to have a copy on my "own" host.
So, what's the easiest way to update once and have changes be pushed to both repositories? Mirroring a repository. The following steps will show how to do this from Gitlab to Github. You can also do this from Gitlab to Gitlab or Github to Github.
The steps to take
-
On GitHub create a new repository, to which the repository on GitLab will mirror.
-
Copy the SSH link you'd use to clone the repository. This should be git@github.com:USERNAME/REPOSITORY.git
-
From within a GitLab project use the gear icon to select Repository and there go to Mirroring repositories and click Expand.
-
In the Git repository URL field, paste the SSH link copied in step 2.
-
Add ssh:// in front of the link and replace the : with a /.
-
At Mirror direction select Push (We're pushing from GitLab to GitHub).
-
Click the Detect host keys button.
-
Set Authentication method to SSH Public key.
-
Click the green Mirror Repository button.
-
Click the Copy SSH public key button, which looks like a clipboard.
-
Go back to GitHub.
-
Go to Settings and there click on Deploy Keys.
-
Click the Add deploy key button on the top right of the page.
-
In the Title field add a title to identify the key. Something like GitLab.
-
In the Key field, paste the key you copied in step 10. Don't edit anything you just pasted.
-
Tick the Allow write access checkbox and click the Add key button.
-
Go back to GitLab.
-
Click the Update now button, whick looks like two arrows.
-
Give it some time, then refresh the page and check if the Last successful update field changes from Never to x minutes ago.
-
You can double check by going back to GitHub and refreshing the Deploy keys page too. Never used should change to Last used within the last week — Read/write.
-
Profit!
- Home
- Next: My i3 config: Part three - SwitchLaunch
- Previous: GNU/Stow and dotfiles