Skip to content
Latchkey

pre-commit install: Wire Hooks Into Git

pre-commit install places a git hook script at .git/hooks/pre-commit so configured hooks run on every commit.

install is a one-time local setup step. It does not run any hooks itself; it only wires pre-commit into git so future commits trigger it.

What it does

pre-commit install writes a small shim into .git/hooks for the requested hook type (pre-commit by default). After that, git invokes pre-commit on each matching action. It reads .pre-commit-config.yaml at run time, not at install time.

Common usage

Terminal
pre-commit install
# also install the commit-msg hook (e.g. for commitizen)
pre-commit install --hook-type commit-msg
# install hook envs up front so the first commit is not slow
pre-commit install --install-hooks

Options

FlagWhat it does
--hook-type <type>Which git hook to install: pre-commit, commit-msg, pre-push, etc.
-t <type>Short form of --hook-type (repeatable)
--install-hooksCreate all hook environments now instead of on first run
--overwriteReplace an existing legacy hook script
-f / --allow-missing-configInstall even if the config file is absent

In CI

You almost never run pre-commit install in CI. Installing the git hook only matters for interactive commits; in a pipeline you call pre-commit run --all-files directly. Cache ~/.cache/pre-commit so the hook environments built on the first run are reused on later jobs.

Common errors in CI

"Cowardly refusing to install hooks with core.hooksPath set" means git is configured with a custom hooksPath (common with Husky or a corporate template); unset it with git config --unset-all core.hooksPath. "[ERROR] No .pre-commit-config.yaml file was found" means you are not at the repo root or the file is missing; add --allow-missing-config only if that is intentional.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →