Created
August 4, 2015 21:34
-
-
Save ianmcnally/c28737154a07644c52e5 to your computer and use it in GitHub Desktop.
Stopping force pushes to master
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 | |
protectedBranch='master' | |
currentBranch=$(git rev-parse --abbrev-ref HEAD) | |
lastCommand=$(ps -ocommand= -p $PPID) | |
disallowedCommand='force|\-f' | |
if [[ $lastCommand =~ $disallowedCommand ]] && [ $currentBranch = $protectedBranch ]; then | |
echo "Force pushing to $protectedBranch is not allowed. Your push is rejected." | |
exit 1 | |
fi | |
exit 0 |
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 | |
# the shell scripts path is relative to the .git/hooks directory | |
ln -s -f ../../prepush.sh .git/hooks/pre-push |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Assumes both scripts are at the root of the directory.