Question about git shell command to push to multiple remotes


I need help to create a shell command to push to multiple remotes.

In my case I need to push the same code to two different heroku repos and one GitHub repo.

These are the remotes set up currently in the project:

git remote -v 
backend (fetch)
backend (push)
generic (fetch)
generic (push)
origin (fetch)
origin (push)

I have created a shell file in my home directory and set the permissions to that file.

This is the current content of that file:

echo "What is the commit message?" 
read commitMessage cd GitHub/project/backend 
git add . 
git commit -am commitMessage 
git push heroku master

Do I need to change the setup of the current git remotes and what in my shell code do I need to change to use one push to all to all the three repos?


The only problem with the script (assuming the lack of a newline between commitMessage and cd is a typo) is that you don’t have a remote named heroku. Replace the last line with

for remote in backend generic origin; do
  git push "$remote" master

You just need to repeat the git push command for the three remotes that are defined.

Answered By – chepner

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published