Skip to content

Instantly share code, notes, and snippets.

@mschartman
Created February 3, 2014 19:47
Show Gist options
  • Save mschartman/8791014 to your computer and use it in GitHub Desktop.
Save mschartman/8791014 to your computer and use it in GitHub Desktop.
Pre-commit hook to warn you if you are committing directly to master.
if [ "$(git rev-parse --abbrev-ref HEAD)" == "master" ]
then
exec < /dev/tty
read -p "You are on the master branch, are you sure you want to commit? (y/N) " -n 1 -r
if [ "$REPLY" = "" ]; then
REPLY='N'
fi
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
read -p "Are you really sure? (y/N) " -n 1 -r
if [ "$REPLY" = "" ]; then
REPLY='N'
fi
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
echo "Tread lightly...\n"
else
echo "Aborted.\n"
exit 1
fi
else
echo "Aborted.\n"
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment