【发布时间】:2011-10-01 15:20:13
【问题描述】:
我们有:
- 带有某个项目的远程存储库。
- 几个远程存储库,我想与前一个同步。
当在第一个项目中推送某些内容时 (1),我需要将这些更改拉到其他远程存储库 (2)。
我可以从第一个 repo 中提取并推送到目标存储库。
最简单的方法是什么?
谢谢。
【问题讨论】:
标签: git version-control synchronization multiple-repositories
我们有:
当在第一个项目中推送某些内容时 (1),我需要将这些更改拉到其他远程存储库 (2)。
我可以从第一个 repo 中提取并推送到目标存储库。
最简单的方法是什么?
谢谢。
【问题讨论】:
标签: git version-control synchronization multiple-repositories
您可以从您无法控制的上游存储库克隆一个新的裸镜像存储库,例如与:
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
这假设您已将 repo1 和 repo2 添加为远程,并且它们指向您只想用作镜像的裸存储库。 (后一个要求是因为您使用的是--force,所以如果其他人将他们的工作推送到repo1 或repo2,它将被自动镜像推送覆盖。)
【讨论】:
git push --mirror --force repo1 我得到了fatal: remote part of refspec is not a valid name in :capabilities^{} fatal: The remote end hung up unexpectedly
git show-ref 输出中的每个引用并尝试单独推送它来查看是否存在导致问题的特定引用,例如git push refs/heads/test-branch:refs/heads/test-branch
git push --all --force repo1 成功。我不知道为什么 :) 按规格 - 这些标志非常相似。
git show-ref 中的git push --all --force repo1 之后出现了新的参考refs/remotes/repo1/master。然后git push --mirror --force repo1 工作。 wtf?! =)
--mirror 的推送也为我工作(并且应该工作)。
您可以在第一个远程存储库中设置post-receive hook,然后从您的第一个远程存储库推送到其他每个远程存储库。
【讨论】: