The Gatekeeper Before Your Git Commits: Pre-commit
A handy tool to auto-check code quality and make every Git commit more reliable.

Make your Git commits safer! No complex setup required. Just install and commit with confidence.
Use pre-commit to automatically run format checks and tests before committing.
Easy to install and configure. Instantly improve your code quality.
pre-commit
is a type of Git Hooks
that runs before each commit.
It allows you to configure custom commands, often used to improve code quality—like format checks or unit tests.
Installation
You can install it using Homebrew:
brew install pre-commit
Or with pip
or pipx
pip install pre-commit
pipx install pre-commit
To add the pre-commit hook to your project:
pre-commit install
Configuring Pre-commit
Create or edit a .pre-commit-config.yaml
file in the root directory of your project and specify the tools you want to use.
Here’s an example using Python’s isort and black for formatting checks:
repos:
- repo: https://github.com/PyCQA/isort
rev: 6.0.1
hooks:
- id: isort
args: ["--profile", "black", "--filter-files"]
- repo: https://github.com/psf/black
rev: 23.1.0
hooks:
- id: black
To manually run a dry run:
pre-commit run --all-files
If you’re in a hurry and absolutely need to skip the checks, you can bypass them using --no-verify
during commit:
git commit --no-verify