不要这样做:
git push origin --all && git push nodester --all && git push duostack --all
有没有一种只需一个命令就可以完成的方法?谢谢 :)不要这样做:
git push origin --all && git push nodester --all && git push duostack --all
有没有一种只需一个命令就可以完成的方法?谢谢 :)创建一个包含多个仓库URL的all
远程:
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
git fetch --all
命令。 - madheadgit remote | xargs -L1 git push --all
将自动获取任何新的远程。 - khatchadgit remote set-url --add origin nodester-host:path/proj.git
。 - macabeusgit remote | xargs -L1 git push --all
用你想要推送的分支替换master
。
git remote | xargs -L1 -I R git push R master
git config --global alias.pushall '!git remote | xargs -L1 git push --all'
运行 git pushall
现在将会把所有分支推送到所有远程仓库。
xargs: illegal option -- l
的错误提示。后来发现需要使用git remote | xargs -L1 git push
命令。 - baluptonman xargs
命令可以看到,选项-l
已经被弃用,因为它不符合POSIX规范。 - wjandrea[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/*
在命令行配置:
$ 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
如果您只想从repo1
拉取,但对于特定分支specialBranch
要推送到repo1
和repo2
:
[remote "origin"]
url = ssh://git@aaa.xxx.com:7999/yyy/repo1.git
fetch = +refs/heads/*:refs/remotes/origin/*
...
[remote "specialRemote"]
url = ssh://git@aaa.xxx.com:7999/yyy/repo1.git
pushurl = ssh://git@aaa.xxx.com:7999/yyy/repo1.git
pushurl = ssh://git@aaa.xxx.com:7999/yyy/repo2.git
fetch = +refs/heads/*:refs/remotes/origin/*
...
[branch "specialBranch"]
remote = origin
pushRemote = specialRemote
...
请参见https://git-scm.com/docs/git-config#git-config-branchltnamegtremote。
git push
而无需任何参数。 - Huskygit remote set-url --push --add origin
命令来设置repo1。无论如何,使用git remote -v
命令检查您的远程仓库。 - Muhammad Yasirroni# 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相同的操作。只不过你是通过命令行完成而非直接编辑配置文件。
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
}
例子:假设您的仓库有三个远程仓库:rem1、rem2和rem3。
# Pushes to rem1
GitPush rem1
# Pushes to rem1 and rem2
GitPush rem1 rem2
# Pushes to rem1, rem2 and rem3
GitPush
如果您已经有一个现有的存储库,并且将origin
作为默认远程,想要通过仅调用git push
(或使用IDE /文本编辑器的git同步按钮)推送到多个远程存储库,请首先将当前的origin
URL(用于所有操作,例如push
、pull
、fetch
)添加为特定于推送的远程源URL:
git remote set-url --push --add origin "$(git remote get-url --push origin)"
...然后将每个远程仓库添加到特定于push的URL中,如下所示:
git remote set-url --push --add origin "git@github.com:username/repo-name.git"
现在所有的获取和拉取操作只会从您的原始远程仓库中获取。
但是通过简单的git push
,Git会将您最新的更改推送到您当前添加的所有远程仓库。