Git hook

A script Git runs automatically at a point in its workflow, such as pre-commit, which can stop the commit by exiting non-zero.

In more detail

Hooks live in .git/hooks and are named after their event; the commit-msg hook gets the path of the message file and rejects the commit by exiting with a non-zero status. Because .git is never committed, a clone brings no hooks with it; core.hooksPath can point at a tracked folder instead. Anyone can skip them with --no-verify, so checks a team relies on belong in continuous integration.

Example

A pre-commit hook regenerates API clients from the OpenAPI document so generated code is never stale.

Related terms

Taught in

References