Git · Hooks

commit-msg hook

Validates the commit message, for example against Conventional Commits.

Syntax
.git/hooks/commit-msg

Example

Example
#!/bin/sh
grep -qE '^(feat|fix|docs|chore):' "$1" || { echo "Bad message"; exit 1; }

More in this group

post-merge hook pre-commit hook pre-push hook

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course