One of the side-effects of using an external Subversion repository was getting automatic offsite backups on every commit.
I’d like to achieve the same using Git.
i.e. every commit to my local repository automatically commits to an external one so the two repositories are always in sync.
I imagine that a post-commit hook would be the way to go. Does anyone have any specific examples of this?
I wrote a post-commit hook for just this purpose. The hook itself is simple; just add a file named
post-committo your.git/hooks/directory with the following contents:The
post-commitfile should be executable. Also make sure that you add a suitable remote repository with the namemy_remotefor this this hook to work.I also made a symlink named
post-mergethat points topost-commit. This is optional. If you do this you’ll auto-sync after merges as well.UPDATE: If you want to ensure that your server, and your mirror do not get out of sync, and ensure that all branches are also backed up, your
post-commithook can use: