GIT – How to push code to multiple remotes simultaneously

Well, if you are looking for the way to push multiple remotes at the same time, you might be aware of git well enough. We call remote repositories as remotes in git. Pushing changes to remotes would be the part of usualy development cycle.

Some times you may need to push changes to  multiple remotes like github and bitbucket etc. To do so, you can follow below given instructions.

List your existing remotes

You can list all avaible remotes using following command

$ git remote -v

If you don’t have already any(other) remote configured. You can do by using git remote

$ git remote add  remote_name  remote_url

git remote add github

Usually, we push changes by addressing remote name by default origin something like git push origin. You can configure group multiple remotes and give it a name. So you push to all those remotes by referring that name.

You can add multiple remotes by using either git remote or git config commands or even you can edit config file.

As git can group multiple remotes. You can follow any of the following way to configure multiple remotes to push simultaneously(no need  all)

Add remotes using git remote

You can set multiple remote urls to single remote using git remote

If you don’t have remote named all already create it using git remote add then use git remote set-url –add to add  new url to existing remote  

git remote set-url all –push –add <remote url>
git remote set-url all  –push –add <another repo remote url>
git remote set-url  –add  all   <another>

You can cross check added new remotes using git remote -v


Group multiple remotes using git config

Command git config is used to configure git parameters. It will edit the .git/config file as per given input

git config –add remote.all.url
git config –add remote.all.url  ssh://user@host/repos/repo.git

Note with out –add option command will replace existing remote url. You can verify updated conf  at .git/config


Edit file .git/config  to add remote and multiple remote urls if you are aware of configuration format.

Now you can push multiple remotes simultaneously by referring remote name which is having multiple remote urls assigned.

git push all master

You can always push to multiple remote repos with out grouping them using formal bash syntax

git push server master && git push github master 

Leave a Reply

Your email address will not be published. Required fields are marked *