Pre-commit Hook Generator
Build a .pre-commit-config.yaml from common hooks.
Overview
Pick from a list of common hooks (linters, formatters, secret scanners, file-size checks, language-specific tools) and the generator produces a ready-to-commit .pre-commit-config.yaml. Drop the file at your repo root, run pre-commit install, and Git will run the chosen checks on every commit.
It's for teams adopting pre-commit as a quality gate - the project that wraps any tool into a Git hook with a single YAML file. Reach for it when standardising a polyglot repo, replacing a hand-rolled .git/hooks/pre-commit, or onboarding a new project to a CI-friendly local check workflow.
How it works
pre-commit (the python framework at pre-commit.com) reads a YAML config that lists repositories of hooks plus the specific hook IDs to run from each. The generator emits the canonical structure: repos: at top level, each repo with repo:, rev: (the commit/tag the hook is pinned to), and hooks: (a list of id: entries).
Hooks ship with sensible defaults and the generator picks ecosystem-appropriate ones - black, isort, mypy for Python; prettier, eslint for JavaScript; gofmt, go-vet for Go; cargo fmt for Rust; plus the cross-cutting pre-commit/pre-commit-hooks (whitespace, EOF, JSON/YAML syntax).
Examples
- Minimal cross-language config:
repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.5.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer - id: check-yaml - Python project:
- repo: https://github.com/psf/black rev: 24.4.0 hooks: [{id: black}] - repo: https://github.com/PyCQA/isort rev: 5.13.2 hooks: [{id: isort}] - JavaScript / Prettier:
- repo: https://github.com/pre-commit/mirrors-prettier rev: v4.0.0-alpha.8 hooks: [{id: prettier}] - Secret scanning:
- repo: https://github.com/gitleaks/gitleaks rev: v8.18.4 hooks: [{id: gitleaks}]
FAQ
How do I install pre-commit?
pip install pre-commit, then run pre-commit install in the repo. After that, Git invokes the hooks automatically on git commit.
Should I pin to a rev:?
Yes - pinning to a specific tag ensures every developer runs the same version. Update with pre-commit autoupdate periodically.
What if a hook fails?
The commit is rejected. Fix the issue, re-stage the files, and try again. Use --no-verify to bypass in an emergency (and only then).
Can I run hooks in CI?
Yes - pre-commit run --all-files in CI catches anyone who bypassed the local hook. Most teams run pre-commit in CI as a backstop.