Last active
October 9, 2020 05:33
-
-
Save area73/9783f2616c82dc451fd070661d3008d2 to your computer and use it in GitHub Desktop.
Prevent git push to master git prehook
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 master. | |
# Based on: https://gist.github.com/stefansundin/d465f1e331fc5c632088 | |
# Global installation instructions | |
# mkdir $HOME/.githooks | |
# git config --global core.hooksPath $HOME/.githooks | |
# curl -fL -o $HOME/.githooks/pre-push https://gist.githubusercontent.com/area73/9783f2616c82dc451fd070661d3008d2/raw/ac5feeed9f4766195e2ec6cd6d85d3a3863cc128/pre-push | |
# chmod +x $HOME/.githooks/pre-push | |
# Uninstall: | |
# rm $HOME/.githooks/pre-push | |
BRANCH=`git rev-parse --abbrev-ref HEAD` | |
PUSH_COMMAND=`ps -ocommand= -p $PPID` | |
if [[ "$BRANCH" == "master" && "$PUSH_COMMAND" =~ push|force|delete|-f ]]; then | |
echo | |
echo "Prevented force-push to $BRANCH. This is a very dangerous command." | |
echo "If you really want to do this, use --no-verify to bypass this pre-push hook." | |
echo | |
exit 1 | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment