Mirror a git repository by pulling?

I am wondering if there is an easy way, ie like a simple cron job, to regularly pull from a remote git repository to a local read only mirror for backup purposes?

Ideally it would pull all branches and tags, but the master/trunk/head would be sufficient.

I just need a way to make sure that if the master git server dies, we have a backup location that we could manually fail over to.


First create a mirror with

git clone --mirror git@somewhere.com:repo.git

then setup a cron job like this:

*/1 * * * * gitbackup cd /backup/repo.git && git fetch -q --tags

This will backup the changesets every minute. Maybe you want to do this less frequently.

As Andrew noted, every clone of a git repo is a full-fledged backup of the repo. That said, if you want something backed up automatically to a particular machine, you can create a bare repo on the backup server, push into it with all the branches you want backed up in order to initially populate it. Then just setup a post update hook on the "main" repo so that as soon as there are commits pushed in, it goes ahead and pushes them to the backup repo. No need for a cron job or rsync, and its an almost live copy.

do you have direct access to the server? then you could just rsync the .git directory


 ? How to mirror only a section of a website?
 ? Mirrored text in textview?
 ? Make Maven Proxy/Server settings configurable based on location?
 ? Mirror Image Diagonally in Python
 ? Flip horizontally an image in Python (JES)
 ? Swift 2.0 Get Mirrored Superclass Properties
 ? cygwin 2.5.2 mirror -- getting the last XP release
 ? Automatically mirroring a GitHub repo
 ? How do I completely mirror a web page?
 ? Swift: Reflecting properties of subclass of NSManagedObject