pre-commit — A Framework for Managing Git Hook Scripts
pre-commit manages and installs multi-language Git hooks from a YAML file. It runs linters, formatters, and checks before commits reach CI — catching issues early with zero manual setup per developer.
What it is
pre-commit is a framework for managing and installing multi-language Git hooks. It reads a .pre-commit-config.yaml file and runs configured hooks (linters, formatters, security checks) before each commit.
pre-commit targets development teams who want to catch issues locally before code reaches CI. It supports hooks written in Python, Node.js, Go, Rust, Ruby, and more -- all managed from one config file.
How it saves time or tokens
pre-commit catches formatting errors, trailing whitespace, YAML syntax issues, and linting violations before they become CI failures. This eliminates round-trip time waiting for remote CI to flag trivial issues. New developers get all hooks installed with a single pre-commit install command.
How to use
- Install pre-commit and initialize hooks:
pip install pre-commit
pre-commit install
pre-commit run --all-files
- Create a
.pre-commit-config.yamlin your repo root.
- Commit as normal. Hooks run automatically on each
git commit.
Example
# .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
types_or: [javascript, typescript, json, yaml, markdown]
Related on TokRepo
- Coding Tools -- Developer productivity and code quality tools
- DevOps Tools -- CI/CD and development workflow automation
Common pitfalls
- Hook environments are cached in
~/.cache/pre-commit/. Clear this cache if hooks behave unexpectedly after version updates. - Large repos may experience slow hook runs. Use the
filesorexcluderegex in hook config to limit scope. - pre-commit hooks run on staged files only by default. Use
pre-commit run --all-filesfor full-repo checks in CI.
Frequently Asked Questions
pre-commit supports hooks written in Python, Node.js, Ruby, Go, Rust, Swift, .NET, Docker, and shell scripts. Each hook declares its language and pre-commit manages the runtime environment automatically.
Use git commit --no-verify or the SKIP environment variable (e.g., SKIP=ruff git commit). This is useful for WIP commits but should not be used as a habit since it defeats the purpose of the hooks.
Yes. Run 'pre-commit run --all-files' in your CI script. This checks every file in the repository, not just staged changes. Many teams use pre-commit.ci as a hosted service that runs hooks automatically on pull requests.
pre-commit creates isolated virtual environments for each hook based on the declared language. Python hooks get their own venv, Node.js hooks get their own node_modules. This prevents dependency conflicts between hooks.
Husky is a Node.js-specific Git hooks manager. pre-commit is language-agnostic and manages hook runtimes for any language. pre-commit also provides a curated ecosystem of community hooks via its registry.
Citations (3)
- pre-commit GitHub— pre-commit is a framework for managing and maintaining multi-language pre-commit…
- pre-commit Official Site— pre-commit hook repository and documentation
- Git Documentation— Git hooks documentation for customizing the commit workflow
Related on TokRepo
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.