Reusable Git hook templates to help enforce safe and consistent workflows across repositories.
These hooks prevent accidental pushes to main and encourage the use of feature branches and pull requests.
- Pre-push protection: Blocks direct pushes to
main. - Easy installation: One-step setup script copies and activates all hooks locally.
- Reusable design: Can be added as a submodule to any repository.
To reuse these hooks across multiple repositories, the repository administrator should set up the submodule once:
git submodule add git@github.com:intelligent-control-lab/git-hooks.git git-hooks
git add .gitmodules git-hooks
git commit -m "Add git-hooks submodule"
git pushAfter this initial setup, the link between your main repository and the git-hooks submodule is saved permanently.
π§© On Future Clones (for the administrator or developers)
Anyone who later clones the main repository only needs to run:
git submodule update --init --recursive
cd git-hooks
./install-hooks.shNo need to run git submodule add again β that command is only required the first time when the administrator sets up the submodule.
π§ͺ Test Your Setup
- Switch to main and try pushing:
git checkout main
git pushYou should see:
π« Direct pushes to main are not allowed.
Please create a feature branch.- Now create a feature branch:
git checkout -b feature/test
git push --set-upstream origin feature/testThe push should succeed normally.
π§° Repository Structure
git-hooks/
βββ pre-push # Hook script that blocks direct pushes to main
βββ install-hooks.sh # Installation script for local setup
βββ README.md # This file
π‘ Notes
β’ The hooks live locally (under .git/hooks) and are not committed with your project.
β’ If you reclone or reset your repository, re-run install-hooks.sh.
β’ You can extend this repo with more hooks (e.g., lint checks, test runners, etc.) as your workflow grows.