【问题标题】:synchronization of several remote git repositories多个远程 git 存储库的同步
【发布时间】:2011-10-01 15:20:13
【问题描述】:

我们有:

  1. 带有某个项目的远程存储库。
  2. 几个远程存储库,我想与前一个同步。

当在第一个项目中推送某些内容时 (1),我需要将这些更改拉到其他远程存储库 (2)。

我可以从第一个 repo 中提取并推送到目标存储库。

最简单的方法是什么?

谢谢。

【问题讨论】:

    标签: git version-control synchronization multiple-repositories


    【解决方案1】:

    您可以从您无法控制的上游存储库克隆一个新的裸镜像存储库,例如与:

    git clone --bare --mirror git://github.com/whoever/whatever.git
    

    (事实上,--mirror 暗示了--bare,所以--bare 并不是绝对必要的。)--mirror 选项表示,与其仅仅从远程获取本地分支并使其成为远程跟踪分支, git 应该镜像远程仓库中所有同名的分支。

    然后,您可以设置一个频繁的 cron 作业,在该存储库中运行以下命令:

    git remote update
    git push --mirror --force repo1 
    git push --mirror --force repo2
    

    这假设您已将 repo1repo2 添加为远程,并且它们指向您只想用作镜像的裸存储库。 (后一个要求是因为您使用的是--force,所以如果其他人将他们的工作推送到repo1repo2,它将被自动镜像推送覆盖。)

    【讨论】:

    • 我在 github 存储库上试过这个,但在 git push --mirror --force repo1 我得到了fatal: remote part of refspec is not a valid name in :capabilities^{} fatal: The remote end hung up unexpectedly
    • @Andrew Kondratovich:这很奇怪,我无法重现。您可能想通过检查git show-ref 输出中的每个引用并尝试单独推送它来查看是否存在导致问题的特定引用,例如git push refs/heads/test-branch:refs/heads/test-branch
    • 看来问题出在 repo1 中。这是新的 empty 存储库,因此没有参考。命令git push --all --force repo1 成功。我不知道为什么 :) 按规格 - 这些标志非常相似。
    • git show-ref 中的git push --all --force repo1 之后出现了新的参考refs/remotes/repo1/master。然后git push --mirror --force repo1 工作。 wtf?! =)
    • @Andrew Kondratovich:再一次,这很奇怪。即使使用新的裸存储库,--mirror 的推送也为我工作(并且应该工作)。
    【解决方案2】:

    您可以在第一个远程存储库中设置post-receive hook,然后从您的第一个远程存储库推送到其他每个远程存储库。

    【讨论】:

    • 我不能 - 存储库不是放在我的服务器上,而是放在 github 或 gcode 上。
    • 好吧,GitHub 至少支持某些钩子 - 见 help.github.com/post-receive-hooks
    • 但这不是我的存储库:)
    猜你喜欢
    • 2014-09-12
    • 1970-01-01
    • 2011-09-16
    • 1970-01-01
    • 2013-03-07
    • 2014-10-19
    • 2014-07-05
    • 2013-01-04
    相关资源
    最近更新 更多