同步多个远程git仓库
我们有:
- 带有一些项目的远程存储库。
- 几个远程存储库,我想将其与上一个存储库同步。
当第一个项目 (1) 中推送某些内容时,我需要将这些更改拉到其他远程存储库 (2)。
我可以从第一个存储库中提取并推送到目标存储库。
最简单的方法是什么?
谢谢。
We have:
- Remote repository with some project.
- Several remote repositories, which I want to synchronize with previous one.
When something pushed in first project (1), I need to pull these changes to other remote repositories (2).
I can pull from first repo and push to destination repositories.
What is the simplest way to do this ?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以从您无法控制的上游存储库克隆一个新的裸镜像存储库,例如使用:(
事实上,
--mirror
意味着--bare
,所以< code>--bare 并不是绝对必要的。)--mirror
选项表示,git 应该不只是从远程获取本地分支并使它们成为远程跟踪分支使用相同的名称镜像远程存储库中的所有分支。然后,您可以设置一个频繁的 cron 作业,在该存储库中运行以下命令:
这假设您已将
repo1
和repo2
添加为遥控器,并且它们指向到您只想用作镜像的裸存储库。 (后一个要求是因为您使用的是--force
,因此如果其他人将其工作推送到repo1
或repo2
,则将被自动镜像推送覆盖。)You could clone a new bare mirror repository from the upstream repository that you have no control over, e.g. with:
(In fact,
--mirror
implies--bare
, so--bare
isn't strictly necessary.) The--mirror
option says that rather than just take the local branches from the remote and make them remote-tracking branches, git should mirror all the branches from the remote repository with the same names.Then, you can set up a frequent cron job that runs the following commands in that repository:
This assumes that you've added
repo1
andrepo2
as remotes, and that they point to bare repositories that you're only wanting to use as mirrors. (The latter requirement is because you're using--force
, so if other people are pushing their work torepo1
orrepo2
, it'll get overwritten by the automated mirror pushes.)您可以在第一个中设置
post-receive
挂钩远程存储库,然后从您的第一个远程存储库推送到其他每个远程存储库。You could set up a
post-receive
hook in the first remote repository that then pushes from your first remote repository to each of the others.