Skip to content

[git] Setting up pre commit hooks

Lojack edited this page Feb 2, 2023 · 2 revisions

Git allows pre-commit hooks to run to help catch errors before committing them. The pre-commit hooks configured for this repository are lightweight checks (so not building a standalone or running pytest) that can be run and caught before the GitHub CI finds them.

Installing

  1. Install pre-commit:
    > pip install pre-commit
    
  2. Install the hooks:
    > pre-commit install
    

Uninstalling

  1. If you decide you don't want the hooks anymore, just run
    > pre-commit uninstall
    

NOTE: If you work on a branch that doesn't have .pre-commit-config.yaml, you'll have to temporarily uninstall the pre-commit hook.

That's it! Now any commits you make will have the hooks run on them to check for easy to find errors. Note that these checks are only run on modified files.

The first time the hooks are run, pre-commit will setup some virtual environments for them which might take a little bit. You can "preload" these virtual environments and check all files using pre-commit run --all-files.

Clone this wiki locally