-
-
Save sa-mm/539362ff431543b7639be17b9e181627 to your computer and use it in GitHub Desktop.
Blocks push to master unless `-n` flag is provided
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 | |
# Stops accidental pushes to master. Adapted from https://gist.github.com/ColCh/9d48693276aac50cac37a9fce23f9bda | |
# Install in project: | |
# install or symlink at .git/hooks/pre-push | |
# chmod +x .git/hooks/pre-push | |
#!/bin/bash | |
protected_branch='master' | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
if [ $protected_branch = $current_branch ] | |
then | |
echo -en "\033[31mPush to master? [y|n] \033[0m" | |
echo -en "\033[1m" | |
read -n 1 -r < /dev/tty | |
echo -en "\033[0m" | |
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