⚡ CHAPTER · GIT HOOKS
Chef You

Automated
Quality Guards

What if Git could run checks automatically before every commit or push? That's what hooks do — scripts that fire at specific Git events.

Scene I

The hook pipeline

Chef You

Hooks live in .git/hooks/. The most popular ones:

pre-commit — lint & format before commit
commit-msg — validate commit message
pre-push — run tests before pushing

If any hook fails, the action is blocked. Try committing with different code quality:

⚡ HOOK PIPELINE Choose a commit to test the hooks
Clean Code
⚠️ Lint Errors
📝 Bad Commit Msg
🐛 Failing Tests
pre-commitLint & format checkPENDING
commit-msgValidate message formatPENDING
pre-pushRun test suitePENDING
Result

Loading…

$ cat .git/hooks/pre-commit
#!/bin/sh
npm run lint
if [ $? -ne 0 ]; then
echo "Lint failed! Fix errors."
exit 1 # blocks commit
fi
Epilogue
Hooks catch mistakes early.
Pass = commit allowed.
Fail = blocked until fixed.

Pro tip: use Husky or lefthook to share hooks with your team via package.json.