Last active
August 14, 2018 14:51
-
-
Save cy4n/f53cb7ad593637b10f3c46cb14e73e9f to your computer and use it in GitHub Desktop.
pre-push hook to prevent from accidently pushing to master/develop/whateverbranch
This file contains 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 | |
## add your branches here, like | |
## protected=('master' 'development' 'yourbranch') | |
protected=('master' 'develop') | |
current_branch=$(git rev-parse --abbrev-ref HEAD) | |
if (printf '%s\n' "${protected[@]}" | grep -xq $current_branch) | |
then | |
read -p "really push to $current_branch? [y|n] " -n 1 -r < /dev/tty | |
echo | |
if echo $REPLY | grep -E '^[Yy]$' > /dev/null | |
then | |
exit 0 # push will execute | |
fi | |
exit 1 # push will not execute | |
else | |
exit 0 # push will execute | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
chmod +x .git/hooks/pre-push