Skip to content

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: flake8
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: flake8

Install and run

pre-commit install
pre-commit run --all-files
pre-commit install
pre-commit run --all-files

Tip

Still keep CI checks—hooks are helpful but not a replacement.

If this helped you, consider buying me a coffee ☕

Buy me a coffee

Was this page helpful?

Let us know how we did