Skip to content

Instantly share code, notes, and snippets.

@DanielBlanco
Created November 8, 2016 16:17
Show Gist options
  • Save DanielBlanco/ea14ea77c620047ab718e8c8a9e5d895 to your computer and use it in GitHub Desktop.
Save DanielBlanco/ea14ea77c620047ab718e8c8a9e5d895 to your computer and use it in GitHub Desktop.
Git hook to prevent pushing to master mistakes.
#!/bin/bash
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
@DanielBlanco
Copy link
Author

Add this file to your .git/hooks/ project directory.

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