Last active
January 21, 2016 13:02
-
-
Save mikechernev/c99f5223d611b312473f to your computer and use it in GitHub Desktop.
Git hook for preventing pushes to protected branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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