How to write good Git commit messages

Posted in til · Tagged with git
Updated August 9, 2025 · 2 minute read
how-to-write-good-git-commit-messages

Why?

A clear, consistent commit message format helps:

  1. Quickly understand project history
  2. Filter and find specific changes (e.g. documentation vs. code)
  3. Generate changelogs automatically (see below for details)

Use the Conventional Commits standard:

Terminal window
<type>(<scope>): <description>
[optional body]
[optional footer]
  • Header/Subject (type + scope + description) is required
    • Keep the subject line under 72 characters
  • Body and footer are optional

Common Types

TypeDescription
featNew feature
fixBug fix
docsDocumentation changes
styleFormatting, whitespace, etc. (no code change)
refactorCode refactor (no bug fix or feature)
perfPerformance improvement
testAdding or updating tests
choreRoutine tasks (build, dependencies, etc.)

Writing Good Commit Messages

  • Use imperative, present tense: “Fix bug” not “Fixed bug”
  • Capitalize the subject line
  • No period at the end of the subject

Example commit messages:

Terminal window
feat(auth): add login with Google OAuth
fix(api): handle token refresh errors
docs(readme): update setup instructions

Helper Tools

ToolWhat It DoesWhen It’s Used
commitizenInteractive CLI that guides you through writing a commit messageBefore writing commits
commitlintLints commit messages to ensure they meet the standard and enforce consistency 1After writing commits
conventional-changelogAutomatically generates changelogs from commit historyAfter merging/releasing

Example workflow:

  1. Write commits using the Conventional Commits format.

  2. Run npx conventional-changelog -i CHANGELOG.md -s to update your changelog.

    This command scans your commit history for Conventional Commits, generates a changelog, writes it to CHANGELOG.md (-i CHANGELOG.md), and updates the file in place (-s). The default preset is Angular, but you can omit -p angular for most projects.

    💡 To see all available command line parameters, run: conventional-changelog --help

  3. Optionally, use standard-version or release-it to bump versions and update changelogs automatically.

Footnotes

  1. You can add a Git hook (commit-msg) to validate your commit messages: npx commitlint --edit $1

Thanks for reading! If you found this page useful, you can support my work by buying me a coffee.
© 2025 Hua-Ming Huang • licensed under CC BY 4.0