How to push to multiple git repos at once

Josh Sherman
1 min read
Command-line Interface Version Control

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 [email protected]:username/project.git
git remote set-url --add --push origin [email protected]:username/project.git

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

Join the Conversation

Good stuff? Want more?

Weekly emails about technology, development, and sometimes sauerkraut.

100% Fresh, Grade A Content, Never Spam.

Related Articles