我可以在git的单个命令中推送到多个存储库吗?
时间:2020-03-06 15:03:21 来源:igfitidea点击:
基本上我想做类似git push mybranch to repo1,repo2,repo3
之类的事情。
现在我只是多次键入push,如果我急于完成推送,我会将它们全部发送到后台git push repo1&git push repo2&
我只是想知道git是否本身支持我想做的事情,或者那里是否有一个聪明的脚本,或者是一种编辑本地repo配置文件的方式,说应该将分支推送到多个远程服务器。
解决方案
我要做的是只有一个裸存储库,该存储库位于我推送到的主目录中。然后,该存储库中的更新后挂钩会将推送或者rsync推送到其他几个公开可见的位置。
这是我的钩子/更新后:
#!/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
即使git remote命令似乎没有暴露我检查过的最后一个,我们也可以在git中为每个遥控器设置多个URL。在.git / config
中,输入如下内容:
[remote "public"] url = [email protected]:kch/inheritable_templates.git url = kch@homeserver:projects/inheritable_templates.git
现在我们可以说git push public
一次推送到两个仓库。