6

I have a repository on GitHub and an empty repository at 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?

Community
  • 1
  • 1
Borneq
  • 261
  • 1
  • 6
  • 13

2 Answers2

4

Keep two separate remote one for google code and another for 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. 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
gnuanu
  • 2,252
  • 3
  • 29
  • 42
  • For example, I have project ScintWrapper on SourceForge and GitHub(main), I must git remote add origin https://github.com/borneq/ScintWrapper.git and git remote add sf ssh://borneq@git.code.sf.net/p/scintwrapper/code; what is difference between master and origin? – Borneq Sep 30 '13 at 13:26
  • You are correct. Origin is the default name given to the remote by git if you clone your local copy from a repo (of course you may change it, it's just an identifier) and master is the main (default) branch of every repo. if you just do a `git pull` or `git push` without specifying a remote to fetch from and a branch to merge with, it will fetch from `origin`(if origin is available) and merge with `master` – gnuanu Oct 01 '13 at 05:44
2

I'm afraid neither Github nor Source Forge offers mirroring functionality.

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. 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. 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. 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.