Skip to content

Instantly share code, notes, and snippets.

@ianmcnally
Created August 4, 2015 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianmcnally/c28737154a07644c52e5 to your computer and use it in GitHub Desktop.
Save ianmcnally/c28737154a07644c52e5 to your computer and use it in GitHub Desktop.
Stopping force pushes to master
#!/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
#!/bin/sh
# the shell scripts path is relative to the .git/hooks directory
ln -s -f ../../prepush.sh .git/hooks/pre-push
@ianmcnally
Copy link
Author

Assumes both scripts are at the root of the directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment