Skip to content

Instantly share code, notes, and snippets.

@vikeri
Last active August 29, 2019 07:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vikeri/ade27cd96f1e1b32d67f3739d9d7d752 to your computer and use it in GitHub Desktop.
Save vikeri/ade27cd96f1e1b32d67f3739d9d7d752 to your computer and use it in GitHub Desktop.
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