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?
CodePudding user response:
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
done
You just need to repeat the git push
command for the three remotes that are defined.