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 https://github.com/my_repo/backend.git (fetch) backend https://github.com/my_repo/backend.git (push) generic https://git.heroku.com/generic-backend.git (fetch) generic https://git.heroku.com/generic-backend.git (push) origin https://git.heroku.com/it-backend.git (fetch) origin https://git.heroku.com/it-backendo.git (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
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 done
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