Course contentsShow
← Software Engineering
Lesson 109 of 1,9333. Collaboration with GitFree lesson

Writing Effective Commit Messages

Master the structure of good commit messages: imperative mood, subject line format, and when to include body text.

Writing Effective Commit Messages

What you'll learn: How to write clear, professional commit messages that help your team understand what changed and why.

Why Commit Messages Matter

A commit message is like a sticky note you leave for your future self and teammates. When someone (including you, six months from now) looks at the project history, they should instantly understand what each commit does without having to read the code.

The Structure of a Good Commit Message

Use the Imperative Mood

Write your subject line as if completing the sentence: "If applied, this commit will..."

✅ Good: Add user authentication
❌ Bad: Added user authentication or Adding user authentication

Think of it like giving a command or instruction. This matches how Git itself writes messages (e.g., "Merge branch...").

Subject Line Format

  • Keep it under 50 characters (like a headline)
  • Capitalize the first word
  • No period at the end
  • Be specific but concise

✅ Fix login button alignment on mobile
❌ fixed stuff or Updated the login page button CSS styling issues

When to Include Body Text

For simple changes, the subject line is enough. Add a body (after a blank line) when you need to explain:

  • Why you made the change (not just what)
  • Any important trade-offs or decisions
  • References to issues or tickets
Fix login button alignment on mobile

The button was overflowing on screens smaller than 375px.
Changed fixed width to responsive flex layout.

Fixes #234

Key Takeaway: Write commit subjects in imperative mood, keep them short and descriptive, and add body text when the "why" matters—your future teammates (and yourself) will thank you.