Commit d2e06e9b authored by Kirk Lange's avatar Kirk Lange

Edited gh mirror post

parent 13d34dea
......@@ -7,8 +7,8 @@ author: Kirk Lange
summary: Leaving GitHub but still want to keep your repos up-to-date?
categories: how-to
thumbnail: fab fa-gitlab
redditurl: 7deu8p
twitterurl: 961084879432597504
redditurl:
twitterurl:
tags:
- gitlab
- github
......@@ -21,60 +21,57 @@ tags:
As I was migrating from GitHub to GitLab on Monday, I began to imagine the
awkward conversation I would have if I was ever in a Microsoft interview. Heck,
maybe the GitHub vs GitLab discussion will become a religious debate like tabs
vs spaces — the last thing I'd want to get into while networking.
the GitHub vs GitLab discussion could become a religious debate like tabs vs
spaces depending on who you talk to — the last thing I'd want to get into
while networking.
After sleeping on it, I decided the best solution would be to have GitHub
mirror all my GitLab repositories. But how?! (Unlike GitLab, GitHub does not
have a "Mirror Repository" option when creating a new project.)
mirror all my GitLab repositories. That way, anyone I'm showing my code to can
use their prefered platform and I don't have to risk getting into an argument.
Only problem is, unlike GitLab, GitHub does not have a "Mirror Repository"
option when creating a new project... Time for a work-around!
# Solution
As it turns out, git allows you to push to multiple URLs simply by adding
one line to your `.git/config`! Here is the relevant excerpt from this
website's repo.
one line to your `.git/config`! Here is the relevant excerpt from
<a target="_blank" href="https://gitlab.com/kirklange/kirklange.gitlab.io">
this website's repo</a>.
```
[remote "origin"]
url = git@gitlab.com:kirklange/kirklange.gitlab.io.git
url = git@github.com:kirklange/kirklange.github.io.git
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = git@gitlab.com:kirklange/kirklange.gitlab.io.git
pushurl = git@github.com:kirklange/kirklange.github.io.git
```
Notice how there are two URLs. Whenever you execute `git push` or `git pull`,
it does so for each one. Even if you are pushing to two remote repos that
aren't in sync, git will account for this and push to what is necessary for
each repo. In other words, if you've only been pushing to GitLab since you
switched, your GitHub repo will catch up like nothing ever happened. (Your
green squares should even sync up!)
Alternately, you can run this command instead of modifying `.git/config`
directly. It does the exact same thing.
```
git remote set-url origin --add user@example.com:my/repo.git
```
Whenever you execute `git push`, it pushes to each `pushurl`. Even if you are
pushing to two remote repos that aren't in sync, git will account for this and
push what is necessary to each repo. In other words, if you've only been
pushing to GitLab since you switched, your GitHub repo will catch up like
nothing ever happened. (Even your green squares should sync up!)
If you *don't* need the ability to pull from your secondary repo, you'll want
If you also want the ability to *pull* from your secondary repo, you'll want
your `.git/config` to be of this format.
```
[remote "origin"]
url = git@gitlab.com:kirklange/kirklange.gitlab.io.git
url = git@github.com:kirklange/kirklange.github.io.git
fetch = +refs/heads/*:refs/remotes/origin/*
pushurl = git@gitlab.com:kirklange/kirklange.gitlab.io.git
pushurl = git@github.com:kirklange/kirklange.github.io.git
```
In fact, it's probably best to not pull from your secondary repo in order to
avoid the headache of having to merge the two. Afterall, the goal here is only
to have the GitHub repo act as a mirror.
However, it's probably best not to pull from your secondary repo as to
mitigate the chances of having to tediously merge the two. Afterall, the goal
here is only to have the GitHub repo act as a mirror.
# Disclaimer
Fine, this is technically not "mirroring", but until Microsoft catches up to
GitLab, this is the best we can do. Please let me know if you have a better
solution. Thanks!
GitLab and earns our trust (if at all), this is the best we can do. Please let
me know if you have a better solution. If anything comes up, I'll make sure to
update this post and give credit. Thanks!
# Source
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment