Skip to content

Instantly share code, notes, and snippets.

@batmat
Forked from dgageot/post-commit
Created June 2, 2011 16:47
Show Gist options
  • Save batmat/1004787 to your computer and use it in GitHub Desktop.
Save batmat/1004787 to your computer and use it in GitHub Desktop.
#!/bin/sh
# This post-commit hook is designed to serve as a central script for any repository you want to backup (via git bundle)
# based on the original idea of David Gageot https://gist.github.com/736547
# Backup configuration
backupRoot="$HOME/Mes documents/My Dropbox/gitbackup/"
#howManyTime=--since=5.days
howManyTime=-10
branchToBackup=master
# After some testing (under msysgit only for the moment), it seems like whereever you commit, the post-commit hook
# always gets executed from the repository root.
# So, let's just take the repository directory name for the bundle.Even when pwd
currentDirectory=`pwd`
backupFileName=`basename $currentDirectory`
git bundle create "$backupRoot$backupFileName" $howManyTime $branchToBackup
echo "Backup ok (time=$howManyTime,branch=$branchToBackup)"
# TODO/IDEAS
# * Externalize backup script, so that one can decide how&where he wants to backup
# * support many branches to backup if specified
# * Use default "git config" properties to get non-default values for this script
@batmat
Copy link
Author

batmat commented Jun 7, 2011

Note : to enable it on any repository on your machine, put this script in the $GIT_HOME/share/git-core/templates/ and re-run git init in every repository you want to backup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment