Skip to content

Instantly share code, notes, and snippets.

@4np
Last active January 2, 2016 09:39
Show Gist options
  • Save 4np/8284565 to your computer and use it in GitHub Desktop.
Save 4np/8284565 to your computer and use it in GitHub Desktop.
This gist will install a Git pre commit hook that will play a 'push it' sample from the Salt N Peppa song… :P
#!/bin/sh
# get global git template dir
if [ `git config --global init.templatedir` ]; then
TEMPLATE_DIR=`git config --global init.templatedir`
else
# there is no git template dir yet, set it
git config --global init.templatedir ~/.git
TEMPLATE_DIR=~/.git
fi
# create the commit hook dir if it does not yet exist
if [ ! -d '$TEMPLATE_DIR/hooks' ]; then
mkdir -p $TEMPLATE_DIR/hooks
fi
# add post commit hook if it does not yet exist
if [ ! -f $TEMPLATE_DIR/hooks/post-commit ]; then
curl -s -o $TEMPLATE_DIR/hooks/post-commit https://gist.githubusercontent.com/4np/8284393/raw/c4544ec0a4fb2366a7f960df65dd174d0cf64cf9/pushit.sh
chmod gou+rx $TEMPLATE_DIR/hooks/post-commit
echo "installed global post commit hook in "$TEMPLATE_DIR"/hooks"
echo "run 'git init' in every repository to re-initialize it so it will use the newly added hook"
else
echo "there already was a post commit hook, skipped installation..."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment