能够用一个命令推动所有的git遥控器?

而不是做:

git push origin --all && git push nodester --all && git push duostack --all 

有一种方法只用一个命令来做到这一点?

谢谢 :)

推动所有分支到所有遥控器:

 git remote | xargs -L1 git push --all 

或者,如果你想推动一个特定的分支到所有遥控器:

用您想要推送的分支replacemaster

 git remote | xargs -L1 -IR git push R master 

(奖金)为命令创build一个git别名:

 git config --global alias.pushall '!git remote | xargs -L1 git push --all' 

现在运行git pushall将把所有的分支都推送到所有的遥控器上。

创build一个all远程用它的名字几个回购url:

 git remote add all origin-host:path/proj.git git remote set-url --add all nodester-host:path/proj.git git remote set-url --add all duostack-host:path/proj.git 

然后只是git push all --all


这是它在.git/config外观:

  [remote "all"] url = origin-host:path/proj.git url = nodester-host:path/proj.git url = duostack-host:path/proj.git 

如果你总是推动repo1,repo2和repo3,但是总是只从repo1中取出,那么把remote的origin设置为

 [remote "origin"] url = https://exampleuser@example.com/path/to/repo1 pushurl = https://exampleuser@example.com/path/to/repo1 pushurl = https://exampleuser@example.com/path/to/repo2 pushurl = https://exampleuser@example.com/path/to/repo3 fetch = +refs/heads/*:refs/remotes/origin/* 

在命令行configuration:

 $ git remote add origin https://exampleuser@example.com/path/to/repo1 $ git remote set-url --push --add origin https://exampleuser@example.com/path/to/repo1 $ git remote set-url --push --add origin https://exampleuser@example.com/path/to/repo2 $ git remote set-url --push --add origin https://exampleuser@example.com/path/to/repo3 

作为CLI编辑.git / config文件的替代方法,您可以使用以下命令:

 # git remote add all origin-host:path/proj.git # git remote set-url --add all nodester-host:path/proj.git # git remote set-url --add all duostack-host:path/proj.git 

同样的git push all --all工作都在这里。

你已经完成了同样的答案#1。 你刚刚使用命令行而不是原始编辑的configuration文件。

我写了一个简短的bash函数来在一次调用中推送多个遥控器。 您可以指定一个遥控器作为参数,多个遥控器以空格分隔,或者不指定任何遥控器推送到所有遥控器。

这可以添加到您的.bashrc或.bash_profile。

 function GitPush { REMOTES=$@ # If no remotes were passed in, push to all remotes. if [[ -z "$REMOTES" ]]; then REM=`git remote` # Break the remotes into an array REMOTES=$(echo $REM | tr " " "\n") fi # Iterate through the array, pushing to each remote for R in $REMOTES; do echo "Pushing to $R..." git push $R done } 

例如:假设您的回购有3个遥控器:rem1,rem2和rem3。

 # Pushes to rem1 GitPush rem1 # Pushes to rem1 and rem2 GitPush rem1 rem2 # Pushes to rem1, rem2 and rem3 GitPush