Skip to content

Instantly share code, notes, and snippets.

@endymion1818
Created October 18, 2023 15:01
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 endymion1818/4ad929324d95dd52f0f66e6fd301744e to your computer and use it in GitHub Desktop.
Save endymion1818/4ad929324d95dd52f0f66e6fd301744e to your computer and use it in GitHub Desktop.
git pre-push hook
# ~/.git_templates/hooks/pre-push
#!/bin/bash
protected_branch='master'
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
if [ $protected_branch = $current_branch ]
then
echo "${protected_branch} is a protected branch, create PR to merge"
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