Automatically keep a secondary repo in sync with a primary repo?

You can just do a git clone --bare --mirror and periodically do a git fetch to make this happen.

I do it realtimish using a tool called gitmirror I wrote in node.js that I run on a machine at home to receive webhooks from github as well as ad-hoc hooks to sync up commits.

For a non-github example, I have a repo that's used for a couchdb backup that has a commit about once an hour. The cron job basically comes down to this:

# do some backup stuff
git commit -qam "Backup `date`" >> dump.log 2>&1

From there, I have a post-commit hook (.git/hooks/post-commit) that looks like this:

#!/bin/sh
curl -sS http://my.home.machine/gitmirror/bak/repo-name.git

You can accomplish the same thing by pushing from the receiving side. This has the advantage of firing-and-forgetting the payload in the normal case.


Oh, don't do all that, just do:

git --bare fetch

;)

(See this old thread for instance)
If you have added the relevant remote origins to your bare repo, you can fetch in turn each of those origins.