Created
January 27, 2026 09:07
-
-
Save mmagician/c6d5005895465ec7de786e94c911d94b to your computer and use it in GitHub Desktop.
Protected branches pre-push hook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To install:
.git/hooks(no need to tell git)~/.git/hooks, and tell git withgit config --global core.hooksPath ~/.git/hooks