Skip to content

Instantly share code, notes, and snippets.

@idlemoor
Created November 23, 2015 09:06
Show Gist options
  • Save idlemoor/146533f97722b335057e to your computer and use it in GitHub Desktop.
Save idlemoor/146533f97722b335057e to your computer and use it in GitHub Desktop.
Avoid commits to the master branch
#!/bin/sh
#
# .git/hooks/pre-commit
# Avoid commits to the master branch
# dbs 2015-11-23
#
# You need to copy this file to .git/hooks/ in each relevant repository, and
# then you need to make the file executable:
# chmod ugo+x .git/hooks/pre-commit
#
# To circumvent this restriction, use --no-verify, e.g.
# git commit --no-verify -m 'Fix error in master branch'
if [ "$(git symbolic-ref HEAD)" = "refs/heads/master" ]; then
echo "Sorry Tim, you're trying to commit to master again."
echo "To insist on your right to do so, please use '--no-verify'."
exit 1
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment