Skip to content

Instantly share code, notes, and snippets.



Created Jan 29, 2016
What would you like to do?
Share your git hooks in a project: basic script to install them all
# Basic script to set custom project hook and share it with other developpers
# original script from
# cd [path-of-the-script]
# .
# Folders usecase
# /.git
# /.git/hooks
# /dev/ <- this script
# /dev/git-hooks <- path of your hooks
# list of hooks the script will look for
HOOK_NAMES="applypatch-msg pre-applypatch post-applypatch pre-commit prepare-commit-msg commit-msg post-commit pre-rebase post-checkout post-merge pre-receive update post-receive post-update pre-auto-gc"
# relative folder path of the .git hook / current script
# relative folder path of the custom hooks to deploy / current script
# relative folder path of the custom hooks to deploy / .git hook folder
echo "Install project git hooks"
for hook in $HOOK_NAMES; do
# if we have a custom hook to set
if [ -f $LOCAL_HOOK_DIR/$hook ]; then
echo "> Hook $hook"
# If the hook already exists, is executable, and is not a symlink
if [ ! -h $GIT_HOOK_DIR/$hook -a -x $GIT_HOOK_DIR/$hook ]; then
echo " > Old git hook $hook disabled"
# append .local to disable it
mv $GIT_HOOK_DIR/$hook $GIT_HOOK_DIR/$hook.local
# create the symlink, overwriting the file if it exists
echo " > Enable project git hook"
ln -s -f $LNS_RELATIVE_PATH/$hook $GIT_HOOK_DIR/$hook
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.