Skip to content

Instantly share code, notes, and snippets.

@vikeri

vikeri/pre-push

Last active Aug 29, 2019
Embed
What would you like to do?
Prevent from pushing to master
#!/bin/bash
# Copy to .git/hooks/pre-push
# Run chmod +x .git/hooks/pre-push
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
echo "you can't push directly to master"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment