pre-commit

Manage multi-language git hook scripts

TLDR

Install hooks into repository
$ pre-commit install
Run all hooks manually
$ pre-commit run --all-files
Run specific hook
$ pre-commit run [hook_id]
Update hook versions
$ pre-commit autoupdate
Create sample config
$ pre-commit sample-config
Install commit-msg hooks
$ pre-commit install --hook-type commit-msg
Run on specific files
$ pre-commit run --files [file1] [file2]
Clean cached hook environments
$ pre-commit clean

SYNOPSIS

pre-commit command [--all-files] [--files files] [options]

DESCRIPTION

pre-commit manages and runs git hooks as code quality checks. Hooks run automatically before commits, catching issues before they enter the repository.Configuration lives in .pre-commit-config.yaml, listing repositories and hooks to use. Hooks can check formatting, lint code, validate files, or run any custom command.Each hook runs in an isolated environment, automatically installed and cached. This ensures consistent behavior regardless of developer's local setup. Language-specific environments (Python, Node, Ruby, etc.) are supported.Common hooks include: trailing-whitespace, end-of-file-fixer, check-yaml, check-json, black, flake8, prettier, eslint. The hook ecosystem provides ready-made checks for most needs.Autoupdate fetches latest hook versions from repositories. The --all-files flag runs against the entire codebase, useful for CI or initial cleanup. Stage-specific hooks (commit-msg, pre-push) enable additional checks.

PARAMETERS

install

Install git hooks.
uninstall
Remove git hooks.
run [hookid_]
Run hooks manually.
autoupdate
Update hooks to latest versions.
sample-config
Generate sample configuration.
clean
Clean cached environments.
gc
Garbage collect unused environments.
try-repo REPO
Try hooks from repository.
--all-files, -a
Run on all files, not just staged.
--files FILES
Run on specific files.
--hook-stage STAGE
Run hooks for stage: pre-commit, pre-push, commit-msg, post-commit, etc.
--hook-type TYPE
Install hooks for type.
--color WHEN
Color output: auto, always, never.
--verbose, -v
Verbose output.

INSTALL

sudo dnf install pre-commit
sudo pacman -S pre-commit
sudo apk add pre-commit
brew install pre-commit
nix profile install nixpkgs#pre-commit

CAVEATS

Initial hook installation can be slow. Requires hooks to be installed per-clone. Some hooks may conflict with each other. Large files slow down commits. Breaking changes in hook updates possible. CI and local environments should match.

HISTORY

pre-commit was created by Anthony Sottile at Yelp around 2014. It addressed the problem of managing git hooks across teams - previously, hooks were often uncommitted or inconsistent. The framework standardized hook management and spawned a large ecosystem of shareable hooks.

SEE ALSO

git-hooks(5), husky(1), lefthook(1), lint-staged(1)