Skip to content

Instantly share code, notes, and snippets.

@mmagician
Created January 27, 2026 09:07
Show Gist options
  • Select an option

  • Save mmagician/c6d5005895465ec7de786e94c911d94b to your computer and use it in GitHub Desktop.

Select an option

Save mmagician/c6d5005895465ec7de786e94c911d94b to your computer and use it in GitHub Desktop.
Protected branches pre-push hook
#!/bin/bash
protected_branches=('next' 'main' 'agglayer')
current_branch=$(git symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
for branch in "${protected_branches[@]}"; do
if [ "$current_branch" = "$branch" ]; then
echo "ERROR: Direct push to '$branch' is not allowed. Use a pull request or bypass hooks."
exit 1
fi
done
@mmagician
Copy link
Author

To install:

  • locally under .git/hooks (no need to tell git)
  • globally under, ~/.git/hooks, and tell git with git config --global core.hooksPath ~/.git/hooks

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