我可以在 git 的单个命令中推送到多个存储库吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/165092/
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
Can I push to more than one repository in a single command in git?
提问by kch
Basically I wanted to do something like git push mybranch to repo1, repo2, repo3
基本上我想做类似的事情 git push mybranch to repo1, repo2, repo3
right now I'm just typing push many times, and if I'm in a hurry to the the pushing done, I just send them all to the background git push repo1 & git push repo2 &
现在我只是多次输入 push,如果我急于完成 push,我只是将它们全部发送到后台 git push repo1 & git push repo2 &
I'm just wondering if gitnatively supports what I want to do, or if maybe there's a clever script out there, or maybe a way to edit the local repo config file to say a branch should be pushed to multiple remotes.
我只是想知道git本机是否支持我想要做的事情,或者是否有一个聪明的脚本在那里,或者可能是一种编辑本地 repo 配置文件的方法来说明一个分支应该被推送到多个遥控器。
回答by Aristotle Pagaltzis
You can have several URLs per remote in git, even though the git remotecommand did not appear to expose this last I checked. In .git/config, put something like this:
您可以在 git 中为每个遥控器设置多个 URL,即使git remote我最后检查的命令似乎没有公开这一点。在 中.git/config,输入如下内容:
[remote "public"]
url = [email protected]:kch/inheritable_templates.git
url = kch@homeserver:projects/inheritable_templates.git
Now you can say “git push public” to push to both repos at once.
现在你可以说“ git push public”一次推送到两个仓库。
回答by Adam Franco
What I do is have a single bare repository that lives in my home directory that I push to. The post-update hook in that repository then pushes or rsyncs to several other publicly visible locations.
我所做的是在我推送到的主目录中拥有一个裸存储库。该存储库中的 post-update 挂钩然后推送或 rsyncs 到其他几个公开可见的位置。
Here is my hooks/post-update:
这是我的钩子/更新后:
#!/bin/sh
#
# An example hook script to prepare a packed repository for use over
# dumb transports.
#
# To enable this hook, make this file executable by "chmod +x post-update".
# Update static info that will be used by git clients accessing
# the git directory over HTTP rather than the git protocol.
git-update-server-info
# Copy git repository files to my web server for HTTP serving.
rsync -av --delete -e ssh /home/afranco/repositories/public/ [email protected]:/srv/www/htdocs/git/
# Upload to github
git-push --mirror github

