Last active
August 29, 2015 14:23
-
-
Save nickcherry/5e3ee870a2ca372465e2 to your computer and use it in GitHub Desktop.
Git Push Confirmation
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 | |
# Inspired by http://dev.ghost.org/prevent-master-push/ | |
# Add this script to the following path in your local git repo: | |
# .git/hooks/pre-push | |
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,') | |
if [ 'master' = $current_branch ] || [ 'staging' = $current_branch ] || [ 'production' = $current_branch ] | |
then | |
read -p "You're about to push ${current_branch}. Is that what you intended? [y|n] " -n 1 -r < /dev/tty | |
echo | |
if echo $REPLY | grep -E '^[Yy]$' > /dev/null | |
then | |
exit 0 # push will execute | |
fi | |
printf "\nWe'll just pretend that never happened. :)\n\n"; 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