Skip to content

Instantly share code, notes, and snippets.

@mikechernev
Last active January 21, 2016 13:02
Show Gist options
  • Save mikechernev/c99f5223d611b312473f to your computer and use it in GitHub Desktop.
Save mikechernev/c99f5223d611b312473f to your computer and use it in GitHub Desktop.
Git hook for preventing pushes to protected branches
#!/bin/sh
#Add to .git/hooks/pre-push
RED='\033[0;31m'
NC='\033[0m' # No Color
protected_branches=(master develop)
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
for branch in "${protected_branches[@]}"
do
if [ $branch = $current_branch ]
then
printf "${RED}[Policy] The push to the '${current_branch}' branch is forbidden!.${NC}\n"
exit 1
fi
done
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment