我可以在git中的单个命令中推送到多个存储库吗?

时间:2008-10-02 23:45:29

标签: git version-control

基本上我想做git push mybranch to repo1, repo2, repo3

之类的事情

现在我只是多次打字,如果我急着完成推送,我只需将它们全部发送到后台git push repo1 & git push repo2 &

我只是想知道git本身是否支持我想要做的事情,或者是否有一个聪明的脚本,或者可能是一种编辑本地repo配置文件的方式来说应该推送一个分支多个遥控器。

2 个答案:

答案 0 :(得分:79)

你可以在git中为每个遥控器提供多个URL,即使git remote命令似乎没有公开我最后检查过的那个。在.git/config中,输入以下内容:

[remote "public"]
    url = git@github.com:kch/inheritable_templates.git
    url = kch@homeserver:projects/inheritable_templates.git

现在你可以说“git push public”立即推送到两个回购站。

答案 1 :(得分:9)

我所做的是有一个裸存储库,它位于我推送的主目录中。然后,该存储库中的更新后挂钩将或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/ afranco@slug.middlebury.edu:/srv/www/htdocs/git/

# Upload to github
git-push --mirror github