home / dev-tools / pre-commit

pre-commit

15k

Git hook manager for installing, updating, and running version-pinned multi-language hooks across repositories.

$pip install pre-commit
Language
Python
Stars
15,112
Category
Dev Tools
Agent
AI Analysis

pre-commit is a Git hook manager that installs and runs version-pinned hooks from many languages through one .pre-commit-config.yaml. It fetches hook repos, provisions isolated runtimes, and executes checks or auto-fixes before commits or in CI.

What It Enables
  • Install Git hook shims and run configured linters, formatters, and policy checks on staged files, all files, or a ref diff.
  • Generate, validate, migrate, and autoupdate hook configuration so repositories keep using current hook revisions without hand-editing every repo.
  • Try hook repositories locally, cache per-hook environments, and reuse the same checks in local commits, pre-push hooks, and CI jobs.
Agent Fit
  • Stable subcommands and exit codes make it straightforward to gate commits or CI jobs with run, validate-config, validate-manifest, and autoupdate.
  • It composes well in shell workflows because you can target explicit files, hook ids, stages, or ref ranges while reusing cached hook environments between runs.
  • Machine-readable output is limited: commands emit plain text and YAML rather than JSON, and most value depends on being inside a Git repo with a maintained .pre-commit-config.yaml.
Caveats
  • It is only useful once a repository is configured with hook repos and a .pre-commit-config.yaml; it is not a general-purpose linter runner by itself.
  • First runs can be slow because hook environments are installed on demand, and some hooks intentionally rewrite files as part of enforcement.