Created
June 23, 2015 22:23
-
-
Save chales/13306eb261da13b5facd to your computer and use it in GitHub Desktop.
Git pre-push hook used to prevent force pushes
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/bash | |
# Prevents force-pushing to proceted branches | |
CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD` | |
PROTECTED_BRANCHES="^(develop|master|release*)" | |
PUSH_COMMAND=`ps -ocommand= -p $PPID` | |
FORCE_OPTION="delete|force|-f" | |
if [[ "$CURRENT_BRANCH" =~ $PROTECTED_BRANCHES && "$PUSH_COMMAND" =~ $FORCE_OPTION ]]; then | |
echo "Prevented force-push to protected branch '$CURRENT_BRANCH'!" | |
echo "You should only Force Push to protected branches if you fully understand the effect." | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment