Git:在一个命令中推送到两个存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5620525/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: Pushing to two repos in one command
提问by Ram Rachum
I want to do git push origin
and git push my_other_remote
in the same line. Possible?
我想做git push origin
和git push my_other_remote
在同一条线上。可能的?
回答by Mark Longair
You can get the same effect by adding an extra push URL for your origin
remote. For example, if the URLs of your existing remotes are as follows:
您可以通过为origin
遥控器添加额外的推送 URL 来获得相同的效果。例如,如果您现有遥控器的 URL 如下:
$ git remote -v
origin me@original:something.git (fetch)
origin me@original:something.git (push)
my_other_remote git://somewhere/something.git (fetch)
my_other_remote git://somewhere/something.git (push)
You could do:
你可以这样做:
git remote set-url --add --push origin git://somewhere/something.git
Then, git push origin
will push to both repositories. You might want to set up a new remote called both
for this, however, to avoid confusion. For example:
然后,git push origin
将推送到两个存储库。但是,您可能需要为此设置一个新的遥控器both
,以避免混淆。例如:
git remote add both me@original:something.git
git remote set-url --add --push both me@original:something.git
git remote set-url --add --push both git://somewhere/something.git
... then:
... 然后:
git push both
... will try to push to both repositories.
...将尝试推送到两个存储库。
回答by Olivier Verdier
You can put the following in the .git/config
file:
您可以将以下内容放入.git/config
文件中:
[remote "both"]
url = url/to/first/remote
url = url/to/other/remote
You can now push to both urls using git push both
.
您现在可以使用git push both
.
If you also want to fetchfrom them (useful for sync) you may add the following lines in your .git/config
file:
如果您还想从它们中获取(对同步有用),您可以在.git/config
文件中添加以下几行:
[remotes]
both = origin, other
Now you can also run git fetch both
.
现在您还可以运行git fetch both
.
回答by Amc_rtty
Just a small addition to the excellent answers provided already - if you dont want to bother with adding "both" and just want to have all operations pushed to both repos automatically, just add your second repo as another url under origin in the git config.
只是对已经提供的优秀答案的一个小补充 - 如果您不想费心添加“两者”并且只想将所有操作自动推送到两个存储库,只需将您的第二个存储库添加为 git 配置中 origin 下的另一个 url。
[remote "origin"]
url = someUrl.git
url = secondUrl.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
Now "git push" uses both.
现在“git push”同时使用两者。