关于git shell命令向多个远程推送的问题



我需要帮助创建一个shell命令来推送到多个远程。

在我的情况下,我需要将相同的代码推送到两个不同的heroku仓库和一个GitHub仓库。

这些是当前在项目中设置的远程:

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)

我已经在我的主目录下创建了一个shell文件,并设置了该文件的权限。

这是该文件的当前内容:

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

我需要改变当前git远程的设置吗?在我的shell代码中,我需要改变什么来使用一个push to all到所有三个repos?

该脚本的唯一问题(假设commitMessagecd之间缺少换行符是一个错别字)是您没有名为heroku的远程。将最后一行替换为

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

您只需要为定义的三个远程重复git push命令。

最新更新