Skip to content

Instantly share code, notes, and snippets.

@felixcarpena
Last active March 2, 2018 08:52
Show Gist options
  • Save felixcarpena/1b00b76237f2f09087df71dde3a1ae8d to your computer and use it in GitHub Desktop.
Save felixcarpena/1b00b76237f2f09087df71dde3a1ae8d to your computer and use it in GitHub Desktop.
git hook pre-push to have a double check before push to master
#!/bin/bash
#extracted from https://dev.ghost.org/prevent-master-push/
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
read -p "You're about to push master, 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
exit 1 # push will not execute
else
exit 0 # push will execute
fi
@felixcarpena
Copy link
Author

This script only work if you are in master branch

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