Running prek for Fast Git Hooks
Table of Contents
Section titled “Table of Contents”- What prek is
- Install prek
- Run prek in an existing pre-commit repo
- Start a new config
- Example
.gitignore - Install Git hooks
- Run hooks manually
- Run prek in GitHub Actions
- Useful prek commands
What prek is
Section titled “What prek is”prek is a Rust-based Git hook manager designed as a fast drop-in replacement for pre-commit.
The important part is that existing .pre-commit-config.yaml files continue to work, so migration is mostly a command swap:
pre-commit runbecomesprek runpre-commit installbecomesprek installpre-commit autoupdatebecomesprek auto-update
Install prek
Section titled “Install prek”Install with uv:
uv tool install prekprek --versionOther common install options:
brew install prekpipx install preknpm add -D @j178/prekRun prek in an existing pre-commit repo
Section titled “Run prek in an existing pre-commit repo”If the repo already has .pre-commit-config.yaml, you usually do not need to rewrite anything.
Run the hooks:
prek runIf you previously installed Git hooks with pre-commit, reinstall the hook shim once with force:
prek install -fRun against the whole repository:
prek run --all-filesStart a new config
Section titled “Start a new config”You can use native prek.toml or keep the ecosystem-standard YAML format.
Example prek.toml:
[[repos]]repo = "https://github.com/pre-commit/pre-commit-hooks"rev = "v6.0.0"hooks = [ { id = "check-yaml" }, { id = "end-of-file-fixer" },]Equivalent .pre-commit-config.yaml:
repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v6.0.0 hooks: - id: check-yaml - id: end-of-file-fixerIf you already use pre-commit, keeping .pre-commit-config.yaml makes migration simplest.
Example .gitignore
Section titled “Example .gitignore”prek does not require a special .gitignore, but this is a practical baseline for a Python repo using Git hooks:
# Python__pycache__/*.py[cod].pytest_cache/.mypy_cache/.ruff_cache/
# Virtual environments.venv/venv/
# Build artifactsbuild/dist/*.egg-info/
# Editor and OS files.DS_Store.idea/.vscode/If your hooks generate files locally, ignore those outputs too. The main rule is that prek run --all-files should not waste time scanning generated junk you never intend to commit.
Install Git hooks
Section titled “Install Git hooks”Install the Git hook shim into .git/hooks:
prek installInstall hooks and prepare environments immediately:
prek install --install-hooksAfter this, Git will run prek automatically during commit for the configured stages.
Run hooks manually
Section titled “Run hooks manually”Run the default staged-file workflow:
prek runRun everything:
prek run --all-filesRun one hook:
prek run end-of-file-fixer --all-filesUpdate pinned hook revisions:
prek auto-updateRun prek in GitHub Actions
Section titled “Run prek in GitHub Actions”If you install prek with uv, a simple workflow looks like this:
name: prek
on: push: branches: [master] pull_request: branches: [master] workflow_dispatch:
jobs: prek: runs-on: ubuntu-latest
steps: - name: Check out code uses: actions/checkout@v4
- name: Install uv uses: astral-sh/setup-uv@v7
- name: Install prek run: uv tool install prek
- name: Run prek run: prek run --all-files --show-diff-on-failureIf you keep prek as a project dependency instead, run it through uv run:
- name: Install dependencies run: uv sync
- name: Run prek run: uv run prek run --all-files --show-diff-on-failureUseful prek commands
Section titled “Useful prek commands”List configured hooks:
prek listSee built-in Rust-native hooks:
prek util list-builtinsA practical migration flow from pre-commit is:
uv tool install prekprek install -fprek run --all-filesprek auto-updateThis keeps the same hook config while replacing the Python-based runner with a single Rust binary. That is the easiest way to start using prek without changing the rest of your workflow.