Last active
October 31, 2020 00:03
-
-
Save mcgwiz/dc30e23293ba7a13a88e00cdc509ea2a to your computer and use it in GitHub Desktop.
pre-push hook to block force-pushing to certain branches on Git for Windows MSYS bash
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 | |
# based on https://gist.github.com/stefansundin/d465f1e331fc5c632088#file-pre-push | |
BRANCH=`git rev-parse --abbrev-ref HEAD` | |
# customization for cygwin/msys | |
PID=`ps | grep ' /cmd/git$' | sort -n | tail -n 1 | tr -s ' ' | cut -d ' ' -f 2` | |
PUSH_COMMAND=`cat /proc/$PID/cmdline | tr '\000' ' '` | |
if [[ "$BRANCH" =~ main|master && "$PUSH_COMMAND" =~ 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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment