2008-10-02 73 views
41

基本上我想做一些像git push mybranch to repo1, repo2, repo3我可以在git中的单个命令中推送到多个存储库吗?

现在我只是打字推了很多次,如果我有急事到了推做的时候,我只是他们都发送到后台git push repo1 & git push repo2 &

我只是想知道,git原生支持我想要做什么,或者如果可能有一个聪明的脚本在那里,或者编辑本地回购配置文件,以说分支应推到多个遥控器。

回答

79

您可以为每个远程多个URL中的git,即使git remote命令似乎没有暴露这最后我检查。在.git/config,把这样的事情:

[remote "public"] 
    url = [email protected]:kch/inheritable_templates.git 
    url = [email protected]:projects/inheritable_templates.git 

现在你可以说“git push public”推到两个回购一次。

10

我所做的只有一个裸存储库,它位于我推入的主目录中。该存储库中的更新后的挂钩然后推送或rsyncs到其他几个公开可见的位置。

这里是我的钩/更新后:

#!/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 
+0

这很好。小心分享或解释git-update-server-info? – kch 2008-10-03 00:00:57

+0

正如我已经添加到答案:git-update-server-info写入一些静态信息文件,将由git客户端通过HTTP而不是git协议访问git目录。 查看以下详细信息: http://www.kernel.org/pub/software/scm/git/docs/git-update-server-info.html – 2008-10-03 22:03:15

相关问题