Last active
February 28, 2019 04:52
-
-
Save M0nica/7d5813acc44391d83a46a013afa386f9 to your computer and use it in GitHub Desktop.
A bash script that can be used in prepush Git hook to warn when pushing changes to master or an otherwise protected branch
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
protected_branch='master' | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
# define bash colors to display | |
yellow='\033[0;33m' | |
red='\033[0;31m' | |
green='\033[0;32m' | |
no_color='\033[0m' | |
if [ $protected_branch = $current_branch ]; | |
then echo "${yellow}You're about to push to $protected_branch, is that what you intended? [y|n]${no_color}" | |
read < /dev/tty | |
if echo $REPLY | grep -E '[^Yy]$' > /dev/null; then | |
echo "${red}This commit has been aborted.${no_color}" | |
exit 1 # push will not execute if there is not explicit 'Y' typed | |
else | |
echo "${green}This commit is proceeding...${no_color}" | |
exit 0 # push will execute | |
fi | |
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