Prek: Faster Git Hooks, Re-engineered in Rust
Prek is a Rust-based reimplementation of the `pre-commit` framework, designed to manage Git hooks with dramatically improved performance and efficiency. It offers a faster, dependency-free alternative that is largely compatible with existing `.pre-commit-config.yaml` files, while also introducing new features like `prek.toml` configuration and built-in monorepo support. The project maintains an active development pace with frequent releases.
Warnings
- gotcha Prek introduced `prek.toml` as an alternative configuration file format to `.pre-commit-config.yaml`. While existing YAML configurations are still supported, new projects or users might find `prek.toml` less error-prone. Converting existing configs can be done with `prek util yaml-to-toml`.
- gotcha The `files` and `exclude` fields in configurations now support glob lists in addition to regular expressions. While this offers more readable and maintainable filters, ensure your patterns are correctly interpreted, especially if mixing glob and regex syntaxes or migrating older, heavily escaped regex patterns.
- gotcha Although `prek` aims for high compatibility with `pre-commit` configurations, the documentation notes that "some languages are not yet supported for full drop-in parity." Users migrating from `pre-commit` with hooks in less common languages should verify support.
- gotcha The `prek` cache can grow over time. The `prek cache gc` command was introduced to clean up unused repositories, hook environments, and tool versions from the cache. Prior to this, manual intervention might have been necessary to manage disk space.
Install
-
pip install prek -
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/j178/prek/releases/download/v0.3.8/prek-installer.sh | sh
Quickstart
# 1. Install prek (if not already done via pip) # curl --proto '=https' --tlsv1.2 -LsSf https://github.com/j178/prek/releases/download/v0.3.8/prek-installer.sh | sh # 2. Generate a sample configuration file prek sample-config > .pre-commit-config.yaml # 3. Install the Git hooks into your repository prek install # 4. Make a change to a file and commit # (e.g., echo 'new content' > some_file.py) git add . git commit -m "My first prek-checked commit"