简体   繁体   English

如何镜像和同步GitHub和SourceForge存储库?

[英]How do I mirror and synchronize GitHub and SourceForge repositories?

I have a repository on GitHub and an empty repository at SourceForge. 我在GitHub上有一个存储库,在SourceForge上有一个空存储库。 How do I make mirrors and synchronize them? 如何制作镜像并同步它们?

On StackOverflow there is " Mirroring a repository across Github, Sourceforge and Google Code " which explains how to push to multiple repositories, but how do I synchronize them when commits will be in GitHub or SourceForge? 在StackOverflow上有“ 镜像Github,Sourceforge和Google代码的存储库 ”,它解释了如何推送到多个存储库,但是当提交将在GitHub或SourceForge中时如何同步它们?

Keep two separate remote one for google code and another for github. 保留两个单独的远程用于谷歌代码,另一个用于github。

git remote add origin <<your google code repo url>>
git remote add github <<your github repo url>>

Now you have two ways to sync the repos. 现在,您有两种方法来同步回购。

git remote update

This will fetch from all remote urls but won't merge. 这将从所有远程URL获取,但不会合并。 You have to merge the code manually. 您必须手动合并代码。 Alternatively if you need all the commits in both of your mirrors you can pull from them separately by specifying a branch name to which the the code to be merged (possibly master). 或者,如果您需要两个镜像中的所有提交,则可以通过指定要合并的代码(可能是主代码)的分支名称来单独提取它们。

git pull origin master
git pull github master

pushing to multiple branches can be done as mentioned in the link in your question or using individual commands 推送到多个分支可以按照问题中的链接或使用单个命令的说明完成

git push origin master
git push github master

I'm afraid neither Github nor Source Forge offers mirroring functionality. 我担心Github和Source Forge都不提供镜像功能。

At first glance I can see two options but both would require a third server (local or in any cloud provider). 乍一看,我可以看到两个选项,但两者都需要第三个服务器(本地或任何云提供商)。 I'm gonna call it sync server. 我要称之为同步服务器。

One option would be to setup your sync server to pull from the source and push to the mirror. 一种选择是将同步服务器设置为从源中提取并推送到镜像。 You could use a simple crontab for that. 你可以使用一个简单的crontab。 If you allow writes on both ends you might have a problem with this approach. 如果您允许两端写入,则可能会遇到此方法的问题。

A second and more complicated option would be to create and setup webhooks (which both github and SF support) on your sync server. 第二个也是更复杂的选择是在同步服务器上创建和设置webhooks(github和SF支持)。 Every time you get a push the webhook will be called and you will be allowed to perform the exact same push to the order git server. 每次推送时都会调用webhook,并且您将被允许执行与订单git服务器完全相同的推送。 This approach is a bit safer but still could fail in case two different pushes happen at same time in both servers. 这种方法有点安全,但如果两台服务器同时发生两次不同的推送,仍然可能会失败。 That's a classical problem in master-master distributed system. 这是master-master分布式系统中的经典问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM