Git Reference

18Hooks

Scripts in .git/hooks/ that run on events. Exit non-zero to block the action.

HookRunsTypical use
pre-commitbefore a commit is createdlint, format, block secrets
commit-msgafter message is writtenenforce Conventional Commits
pre-pushbefore pushingrun test suite
post-checkoutafter switching branchesinstall deps, regenerate files
pre-receiveon the serverenforce 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