Skip to content

Instantly share code, notes, and snippets.

@mertvetsky
Last active March 25, 2016 15:53
Show Gist options
  • Save mertvetsky/4b5ca4f823237ba4ccd8 to your computer and use it in GitHub Desktop.
Save mertvetsky/4b5ca4f823237ba4ccd8 to your computer and use it in GitHub Desktop.
Don't commit to master! (located in .git/hooks/, need +x)
#!/bin/bash
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
read -p "You're about to commit in master, is that what you intended? [y/N] " -n 1 -r < /dev/tty
echo
if echo $REPLY | grep -E '^[Yy]$' > /dev/null
then
exit 0 # commit will execute
fi
exit 1 # commit will not execute
else
exit 0 # commit will execute
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment