Commit d2e06e9b authored by Kirk Lange's avatar Kirk Lange

Edited gh mirror post

parent 13d34dea
...@@ -7,8 +7,8 @@ author: Kirk Lange ...@@ -7,8 +7,8 @@ author: Kirk Lange
summary: Leaving GitHub but still want to keep your repos up-to-date? summary: Leaving GitHub but still want to keep your repos up-to-date?
categories: how-to categories: how-to
thumbnail: fab fa-gitlab thumbnail: fab fa-gitlab
redditurl: 7deu8p redditurl:
twitterurl: 961084879432597504 twitterurl:
tags: tags:
- gitlab - gitlab
- github - github
...@@ -21,60 +21,57 @@ tags: ...@@ -21,60 +21,57 @@ tags:
As I was migrating from GitHub to GitLab on Monday, I began to imagine the 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, 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 the GitHub vs GitLab discussion could become a religious debate like tabs vs
vs spaces — the last thing I'd want to get into while networking. 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 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 mirror all my GitLab repositories. That way, anyone I'm showing my code to can
have a "Mirror Repository" option when creating a new project.) 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 # Solution
As it turns out, git allows you to push to multiple URLs simply by adding 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 one line to your `.git/config`! Here is the relevant excerpt from
website's repo. <a target="_blank" href="https://gitlab.com/kirklange/kirklange.gitlab.io">
this website's repo</a>.
``` ```
[remote "origin"] [remote "origin"]
url = git@gitlab.com:kirklange/kirklange.gitlab.io.git url = git@gitlab.com:kirklange/kirklange.gitlab.io.git
url = git@github.com:kirklange/kirklange.github.io.git
fetch = +refs/heads/*:refs/remotes/origin/* 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`, Whenever you execute `git push`, it pushes to each `pushurl`. Even if you are
it does so for each one. Even if you are pushing to two remote repos that pushing to two remote repos that aren't in sync, git will account for this and
aren't in sync, git will account for this and push to what is necessary for push what is necessary to each repo. In other words, if you've only been
each repo. In other words, if you've only been pushing to GitLab since you pushing to GitLab since you switched, your GitHub repo will catch up like
switched, your GitHub repo will catch up like nothing ever happened. (Your nothing ever happened. (Even your green squares should sync up!)
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
```
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. your `.git/config` to be of this format.
``` ```
[remote "origin"] [remote "origin"]
url = git@gitlab.com:kirklange/kirklange.gitlab.io.git url = git@gitlab.com:kirklange/kirklange.gitlab.io.git
url = git@github.com:kirklange/kirklange.github.io.git
fetch = +refs/heads/*:refs/remotes/origin/* 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 However, it's probably best not to pull from your secondary repo as to
avoid the headache of having to merge the two. Afterall, the goal here is only mitigate the chances of having to tediously merge the two. Afterall, the goal
to have the GitHub repo act as a mirror. here is only to have the GitHub repo act as a mirror.
# Disclaimer # Disclaimer
Fine, this is technically not "mirroring", but until Microsoft catches up to 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 GitLab and earns our trust (if at all), this is the best we can do. Please let
solution. Thanks! 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 # 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