How to push to multiple git repos at once

A while back I fell in love with GitLab, specifically their GitLab Runners. This
was at a time before GitHub had GitHub Actions, so I decided to move the
majority of my git repositories over to GitLab.

Fast forward a few years, GitHub has Actions, and more importantly, it seems
like GitHub is really starting to push forward after a period of stagnation in
their product.

Nothing against GitLab, but GitHub is really the place to be in terms of being
“the hub” for open source software. With the exception GNOME and a few other
Linux-y things, I rarely find myself starring projects over on GitLab.

So, with moving back from GitLab to GitHub, I have a few projects that are still
lingering, so I thought, it would be pretty nice to be able to push code to both
GitLab and GitHub as I work through the remaining transition.

Easy enough, with the git command-line tool, you can set multiple remote
repositories to push to. To do so, you’ll want to do the following for each of
your remote repositories:

git remote set-url --add --push origin YOUR-GIT-SSH-URL

When I say each of your remote repositories, I mean that you need to include the
remote repository that you have cloned locally. If you have a repo on both
GitHub and GitLab, it will look something like this:

git remote set-url --add --push origin git@github.com:username/project.git
git remote set-url --add --push origin git@gitlab.com:username/project.git

With both URLs configured, the next time you do a git push it will push to
both repositories!

Josh Sherman - The Man, The Myth, The Avatar

About Josh

Husband. Father. Pug dad. Musician. Founder of Holiday API, Head of Engineering and Emoji Specialist at Mailshake, and author of the best damn Lorem Ipsum Library for PHP.


If you found this article helpful, please consider buying me a coffee.