pre-commit hooks are fundamentally broken
- Article argues pre-commit hooks are fundamentally broken due to running on working tree, not index, failing to catch unstaged changes.
- Hooks interfere with rebases, interactive commits, and external branches without hooks, requiring frequent
--no-verifyusage. - Demonstrates issues via Rust fizzbuzz example: formatting fixes don't stage, existing unformatted code blocks commits, rebases fail unexpectedly.
- Recommends pre-push hooks instead: run on index, keep fast/reliable (no network/credentials), quiet, manual setup via docs.
- Additional pitfalls: slow/unreliable implementations, modifying commits, not running on stashes; prefers commits over stashes for branching.
Hacker News Discussion
- Users debate pre-commit vs. pre-push/CI: enforce in CI for reliability, use hooks to reduce churn but not guarantee (e.g., secrets in pre-push).
- Workflows vary: WIP commits common, rebase/squash before push; hooks break rebases needing full checkouts (e.g., cargo clippy).
- Editor integration preferred for formatting/linting; force consistency in teams but allow bypass for power users.
- Alternatives: git filters for formatting, jj run for future; personal setups run heavy local checks but optional for contributors.
- Defenses of pre-commit frameworks (speed, environments) countered by author; prefer CI for shared enforcement over local hooks.