Git Commit Messages: best practices that matter
Your commit messages are the documentation of your project's history. Learn the rules, formats, and habits that make them actually useful.
Anatomy of a good commit message
Subject line (required)
A short summary of the change, 50 characters or less. Written in imperative mood ("Add feature" not "Added feature"). No period at the end.
feat: add email verification on signupBlank line (separator)
Always separate the subject from the body with a blank line. Git uses this to distinguish the summary from the description.
Body (optional)
Explain why the change was made, not what (the diff shows the what). Wrap at 72 characters. Reference issues or tickets when relevant.
Users were able to sign up with invalid emails,
leading to bounced notifications. This adds a
verification step before account activation.
Closes #187
7 rules for great commit messages
These conventions are widely adopted in the industry. Follow them and your teammates will thank you.
Keep subject under 50 chars
Forces you to be concise. GitHub truncates after 72 characters anyway.
Capitalize the subject line
"Fix bug" not "fix bug". Start with an uppercase letter for consistency.
No period at the end
The subject line is a title, not a sentence. Every character counts in 50 chars.
Use imperative mood
"Add feature" not "Added feature". Matches Git's own conventions (e.g., "Merge branch").
Blank line before the body
Required for git log, shortlog, and many tools to work correctly.
Wrap body at 72 characters
Git doesn't wrap text automatically. Keep lines readable in terminals and log views.
Explain why, not what
The diff shows what changed. The message should explain the motivation behind the change.
Conventional Commits format
A popular convention that prefixes each message with a type. Enables automated changelog generation and semantic versioning.
feat:A new feature for the user
feat: add dark mode toggle
fix:A bug fix
fix: resolve login timeout issue
docs:Documentation changes only
docs: update contributing guide
refactor:Code change that neither fixes a bug nor adds a feature
refactor: simplify auth middleware
test:Adding or updating tests
test: add e2e tests for checkout
chore:Maintenance tasks (deps, CI, tooling)
chore: upgrade eslint to v9
Good vs bad: spot the difference
Compare a clean git log with a messy one. Which project would you rather join?
Good messages
Bad messages
Before and after: rewriting bad messages
Bad
fix stuffWhat was fixed? Where? Why?
Good
fix: prevent crash when user profile is nullClear type, scope, and what was fixed.
Bad
updated the code for the new design system colors and also changed some button styles and fixed a few things in the headerWay too long, mixing multiple changes, no structure.
Good
refactor: migrate button styles to design system tokensOne change per commit. Split the rest into separate commits.
Bad
WIPNot a commit message. Use branches or stash for work in progress.
Good
feat: add initial search bar component (no results yet)Honest about the state, but still descriptive.
Writing commits: editor vs inline
Use git commit for detailed messages or -m for quick ones.
With editor (detailed)
With -m flag (quick)
Part of the Git Basics guide
GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.
Questions about commit messages
Practice writing great commits in a safe terminal
GitQuest investigations put you in real-world scenarios where clear commit messages make the difference.
Start the investigations