What are Git hooks?
Answer
Git hooks are scripts that Git executes automatically before or after specific Git events, allowing you to automate tasks and enforce policies. They live in .git/hooks/ as executable scripts (shell, Python, Node.js, etc.). Hooks are not committed to the repo by default (they're in .git/) — to share hooks, use tools like husky (Node.js) or put them in a directory and symlink. Common client-side hooks: pre-commit — runs before a commit is created; used to run linters, formatters, tests. Exit non-zero to abort the commit; commit-msg — validates the commit message format (e.g., enforce conventional commits); pre-push — runs before pushing; used to run full test suite; post-commit — runs after commit (notifications); pre-rebase — can prevent rebasing certain branches. Server-side hooks (on the remote): pre-receive — validate pushes before accepting; enforce branch protection; post-receive — trigger deployments, send notifications after push. Tools: Husky — popular Node.js tool for managing Git hooks in package.json; lint-staged — run linters only on staged files.