Advertisement

Git Commit Message Best Practices: The 7 Rules

A git commit message explains what changed and, more importantly, why. Good messages make git log, git blame, and code review dramatically faster.

The 7 Rules

  1. Separate subject from body with a blank line. Lets git log --oneline show just subjects.
  2. Limit subject to 50 characters. GitHub and most UIs truncate at 72; 50 gives breathing room.
  3. Capitalize the subject line. Fix timeout bug, not fix timeout bug.
  4. No period at the end. It is a title, not a sentence.
  5. Use imperative mood. Write Add feature, not Added or Adding.
  6. Wrap body at 72 characters. Keeps messages readable in terminals.
  7. Body explains what and why, not how. The code shows how; the message explains the reason.

Before: fixed stuff

After:
Fix payment gateway timeout on slow connections

Default 30s HTTP timeout too short for high-latency mobile.
Increase to 90s per gateway docs. Fixes #847.

Conventional Commits

Structured prefix format: type(scope): description. Types: feat, fix, docs, refactor, test, chore. Enables automated changelogs and semantic versioning.

feat(auth): add OAuth2 login via Google
fix(payments): handle timeout on slow connections
docs(api): add rate limit section to README

Tip: git log --oneline --graph on a well-maintained project vs a poorly-maintained one shows the difference immediately. Good commit history is a form of documentation.
Advertisement