Git Reference / Hooks
18Hooks
Scripts in .git/hooks/ that run on events. Exit non-zero to block the action.
| Hook | Runs | Typical use |
|---|---|---|
pre-commit | before a commit is created | lint, format, block secrets |
commit-msg | after message is written | enforce Conventional Commits |
pre-push | before pushing | run test suite |
post-checkout | after switching branches | install deps, regenerate files |
pre-receive | on the server | enforce policy on pushes |
# .githooks/pre-commit — share hooks via the repo #!/bin/sh npm run lint || exit 1 $ chmod +x .githooks/pre-commit $ git config core.hooksPath .githooks