1

I am looking for a way to automatically to sync (mirror) one repo on 2 git git servers. Unfortunately i cannot have a single server for permissions reasons.

People should be able to push changes(and branches) to one of the server and those changes should automatically replicate on the other server.

Any Idea on how to do that?

Many thanks

2 Answers2

1

This is well explained under the title "Duplicating a Git repository". Taken from github article:

If you want to mirror a repository in another location, including getting updates from the original, you can clone a mirror and periodically push the changes.

# Make a bare mirrored clone of the repository
git clone --mirror https://github.com/exampleuser/repository-to-mirror.git

# Set the push location to your mirror
cd repository-to-mirror.git
git remote set-url --push origin https://github.com/exampleuser/mirrored

A mirrored clone includes all remote branches and tags, but all local references will be overwritten each time you fetch, so it will always be the same as the original repository. Setting the URL for pushes simplifies pushing to your mirror. To update your mirror, fetch updates and push, which could be automated by running a cron job.

git fetch -p origin
git push --mirror

If you want to automate this via code or a Ruby script, you can do it as well using the Git Duplicator Ruby gem.

khelll
  • 23,590
  • 15
  • 91
  • 109
0

For that you have some deployment systems like Jenkins. There you can add your server and place the command to run on alle servers.

You can install some Jenkins Plugins for SSH for example or use something like Chef / Puppet or Capistrano. There are some tools.

René Höhle
  • 26,716
  • 22
  • 73
  • 82
  • Hi, thanks for your response. What git commands would you run on your Jenkins server to make sure the repositories stay in sync? – Georges Chaudy Oct 20 '14 at 10:52