Skip to content

Instantly share code, notes, and snippets.

@tonicospinelli
Last active December 28, 2015 00:19
Show Gist options
  • Select an option

  • Save tonicospinelli/7412381 to your computer and use it in GitHub Desktop.

Select an option

Save tonicospinelli/7412381 to your computer and use it in GitHub Desktop.
Git Hook Pre Commit - deny commit in main branches
#!/bin/sh
#array with denied branches to commit
uncommitBranches=( "develop" "master" "staging" "production" "live" )
#get the current branch
branch_name="$(git rev-parse --abbrev-ref=strict HEAD 2>/dev/null)"
for i in "${uncommitBranches[@]}"
do
if [ "$i" == "$branch_name" ] ; then
echo " Oops... WAIT!"
echo " You are trying to commit on the $branch_name branch."
echo " Surely you don't mean that?"
echo
echo " If you really do, force the commit by adding --no-verify to the command. Not Recommended"
echo
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment