Skip to content

Instantly share code, notes, and snippets.

@mihai
Last active August 29, 2015 14:17
Show Gist options
  • Save mihai/cf32f741b1bce3280e76 to your computer and use it in GitHub Desktop.
Save mihai/cf32f741b1bce3280e76 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Prevent pushing to `protected_branch`.
# Just place this file in your `.git/hooks` folder and make sure it is executable
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
echo "You're pushing to master, that is NOT ALLOWED"
echo
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