Modernizing Your Dev Stack: Re-engineering Git Hooks with prek
Enter prek (by j178). It’s essentially a high-performance alternative to the classic Python-based pre-commit framework, rebuilt from the ground up in Rust.
As engineers, we love speed and minimal dependencies. Here’s why prek is a step up
Blazing Fast
Being written in Rust, it starts up and executes much faster than the Python implementation. This is crucial because "hook lag" is the number one reason devs start using --no-verify.
Single Binary
No need to worry about whether your teammate has the right Python version or virtualenv set up just to run a linter.
Compatibility
It’s designed to be a drop-in or near-drop-in replacement, so you don't have to relearn everything.
Setting it up is straightforward. Since it's a Rust tool, you can grab it via cargo or direct download.
# Using cargo
cargo install prek
# Or using homebrew (if available/configured)
brew install j178/tap/prek
Navigate to your project root and run
prek install
This sets up the necessary script in .git/hooks/pre-commit that tells Git to look at your prek configuration.
prek uses a .pre-commit-config.yaml file, just like the original framework. This makes migration a breeze.
Here is a sample configuration that runs a formatter (Prettier) and a linter (ESLint/Rust) before every commit
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
stages: [commit]
# Example for a Rust project
- repo: local
hooks:
- id: rust-fmt
name: fix rust formatting
entry: cargo fmt --all --
language: system
types: [rust]
If you want to check all files without committing
prek run --all-files
CI/CD Integration
You can use prek in your CI pipeline to ensure that the code being merged follows the same rules being enforced locally.
Language Agnostic
Even though it’s built in Rust, it can manage hooks written in Node, Python, Go, or simple Shell scripts.
Skip with Intention
If you ever need to bypass it for a quick experimental commit, the standard git commit -m "..." --no-verify still works!