What a pre commit hook is
A pre commit hook is a script git runs before recording a commit. If it exits with an error, the commit is blocked. This catches problems on the developer machine before they reach the shared branch.
What to run
- Format and lint only staged files so the hook stays fast.
- A quick type check on changed code if it is fast enough.
- Block accidental secrets or huge files.
Keep it fast
A slow hook tempts people to bypass it. Run checks on the staged subset rather than the whole repo, and push heavier suites to CI.
Hooks are a convenience, not a guarantee
Anyone can skip a hook with a no verify flag, so the real enforcement still belongs in CI. Treat hooks as a fast local helper that shortens the feedback loop.
A good hook fixes what it can automatically and only blocks on real problems.
Key idea
Pre commit hooks run fast checks on staged files to catch issues early, but CI remains the real gate.