Why push to multiple repos?

+

Do want to use both Github & and a Self-hosted Git Repo? Here’s how I’ve been doing it!

+

I really enjoy self-hosting services that I use everyday. One of those includes a git-style version control software. In my +case, I’ve been running Gitea for a few years now and have been really satisfied with everything (except +for that one time that an update broke all my templates).

+

At the same time, there’s the entire social element that comes with Github along with having your public repositories +available in a place that other developers are already spending time on. Instead of adding, committing, commenting, and +pushing on two different repos, here’s how I run all those commands just once and push it to both repos.

+

Note: An import git note to remember is that you can only push to multiple remote repositories. You’ll have to select +which repo you want to be the main pull repository. Have this be remote-url-one in the below instructions.

+

Command Line Instructions

+

These instructions come after you initialize the repo in your directory. Make sure you have both of your remote git URLs +handy at this point!

+
git remote add {{ remote-name }} {{ remote-url-one }}
+git remote set-url --add --push {{ remote-name }} {{ remote-url-one }}
+git remote set-url --add --push {{ remote-name }} {{ remote-url-two }}
+

To confirm that everything worked as expected, run git remote -v to check your remote repos. You should see one repo in +there twice, once for (push) and once for (fetch).

+

I use the remote name “all” for multiple repos, so here’s what my git remote -v returns:

+
> git remote -v
+all     https://git.rsmsn.co/Normanras/rsmsn_blog.git (fetch)
+all     https://git.rsmsn.co/Normanras/rsmsn_blog.git (push)
+all     https://github.com/Normanras/rsmsn_blog.git (push)
+all     https://git.rsmsn.co/Normanras/rsmsn_ddblog.git (push)
+

To now push to your repositories, after adding and committing run git push {{ remote-name }} --all. My command is +git push all --all (see why I use all, now?)

+

Here’s the man page description on the --all flag:

+
--all
+    Push all branches (i.e. refs under refs/heads/); cannot be used
+    Instead of naming each ref to push, specifies that all refs under
+    end, locally updated refs will be force updated on the remote end,
+    Do everything except actually send the updates.
+    same as prefixing all refs with a colon.
+

And that’s it! You should be able to push everything to both of your repos fairly easily now with this new set commands.

+ + +