Setting up Pre-commit Hooks
What pre-commit does
pre-commitpre-commit runs checks before a commit is created.
This helps:
- keep formatting consistent
- avoid committing broken code
Example .pre-commit-config.yaml
repos:
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8repos:
- repo: https://github.com/psf/black
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8Install and run
pre-commit install
pre-commit run --all-filespre-commit install
pre-commit run --all-filesTip
Still keep CI checks—hooks are helpful but not a replacement.
If this helped you, consider buying me a coffee ☕
Buy me a coffeeWas this page helpful?
Let us know how we did
