Originally published on DevToolHub.

The git commit message conventions I would use are type(scope): description on the first line, a blank line, then an optional body. That is Conventional Commits. Git requires none of it, so a convention only helps if something checks it. I ran everything below on Git 2.56.0.

What Git does with the message

Git treats the text up to the first blank line as the title. With no blank line, fix: line one and line two without blank became one subject: [fix: line one line two without blank].

In an editor, lines that start with # are stripped, so a message of #42 fix login aborted with Aborting commit due to empty commit message. With -m it was kept. Put the issue number in a footer: Refs: #42.

The format

<type>[optional scope]: <description> [optional body] [optional footer(s)] 

feat is a MINOR bump, fix is PATCH, and ! before the colon or a BREAKING CHANGE: footer is MAJOR. Footers can be read with git log -1 --format='%(trailers:key=Co-authored-by,valueonly)'.

A commit-msg hook

#!/bin/sh subject=$(head -n1 "$1") case "$subject" in "Merge "*|"Revert "*) exit 0 ;; esac pattern='^(feat|fix|docs|chore|refactor|test|ci)(\([a-z0-9-]+\))?!?: .{1,72}$' if ! echo "$subject" | grep -Eq "$pattern"; then echo "Commit message must look like: type(scope): description (max 72 chars)" >&2 echo "Got: $subject" >&2 exit 1 fi 

It rejected fixed stuff, accepted fix(login): handle empty password and feat!: drop v1 API, and my first version also rejected git merge until I allowed Merge messages. git revert --no-edit was not blocked, and --no-verify skips the hook. Hooks in .git/hooks are not cloned; share them with git config core.hooksPath .githooks.

Check the PR title in CI

With squash merge, GitHub used the PR title plus the number as the commit subject (Increase test timeout (#1)), so I checked the title with a GitHub Actions workflow on pull_request with the edited type. A bad title failed, and the check passed again after I edited it.

What I did not test

Not tested: commitlint, Husky, pre-commit, semantic-release, required status checks, Windows, or a revert that opens an editor.

Full post with the workflow YAML and FAQ: Git Commit Message Conventions.