pre-commit
pre-commit is a multi-language framework for managing and running code-quality checks as Git hooks, so you can catch problems before changes are committed or pushed. You declare hooks in a .pre-commit-config.yaml file, and pre-commit runs them consistently for everyone on the team.
Installation and Setup
Install the tool and initialize it in a Git repository:
Create a .pre-commit-config.yaml file at the repository root to declare the hooks that should run.
Key Features
- Manages Git hook installation for multiple hook types via
pre-commit install --hook-type ...and related configuration. - Installs each hook in an isolated, language-appropriate environment and reuses installed environments from a cache for faster subsequent runs.
- Pins hook repositories and revisions in
.pre-commit-config.yamlfor reproducible results across machines and CI. - Runs only the relevant files during Git-hook execution. By default,
pre-commitrun runs on currently staged files and supports scanning the whole codebase withpre-commit run --all-files. - Updates pinned hook revisions with a single command (pre-commit autoupdate).
Usage
Create a .pre-commit-config.yaml for a project:
YAML
.pre-commit-config.yaml
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.9 # Pin a Ruff release
hooks:
- id: ruff-check
args: [--fix] # Apply safe fixes
- id: ruff-format
Install the Git hooks for the current repository and run them:
Shell
$ pre-commit install
$ pre-commit run --all-files
By Leodanis Pozo Ramos • Updated Dec. 18, 2025