← All ArticlesTrip Reveal

How to Write Better Git Commit Messages (With Examples)

2026-10-11

# How to Write Better Git Commit Messages (With Examples)

Your commit messages are the history book of your codebase. Six months from now, when you're debugging a production issue at 2 AM or onboarding a new team member, those commit messages are often the only context you have for why a change was made.

Yet most developers treat commit messages as an afterthought. “Fixed stuff.” “Update.” “WIP.” Sound familiar?

The good news: writing better commit messages isn't hard. It takes 30 seconds of thought and saves hours of confusion later. In this guide, you'll learn the anatomy of a good commit message, common mistakes to avoid, and how AI tools can help you maintain consistency across your team.

The Anatomy of a Good Commit Message

A well-crafted commit message has three parts: type, scope, and subject.

The Format

```

():

```

The first line is the most important. It should be concise, descriptive, and follow a consistent format. The body (optional) provides additional context. The footer (optional) references issues or breaking changes.

5 Examples of Good Commit Messages

1. Feature addition:

```

feat(auth): add OAuth2 login with Google

Implement Google OAuth2 authentication flow. Users can now sign in

with their Google account. Added callback handler and session management.

Closes #234

```

2. Bug fix:

```

fix(cart): prevent duplicate items when clicking add button rapidly

Added debounce to add-to-cart handler. Previously, rapid clicks would

add the same item multiple times to the cart.

Fixes #567

```

3. Documentation update:

```

docs(readme): add deployment instructions for AWS

Added step-by-step guide for deploying to AWS ECS. Includes IAM role

setup, task definition, and service configuration.

```

4. Refactoring:

```

refactor(api): extract validation logic into separate module

Moved request validation from route handlers into dedicated validator

module. Improves testability and reduces duplication across endpoints.

```

5. Performance improvement:

```

perf(query): add database index for user email lookups

Added composite index on (email, tenant_id) for user lookups. Reduces

query time from 450ms to 12ms for authentication queries.

```

5 Examples of Bad Commit Messages (And How to Fix Them)

Bad: `fixed stuff`

Better: `fix(auth): resolve token expiration handling`

Bad: `update`

Better: `feat(ui): update button styles to match new design system`

Bad: `WIP`

Better: `feat(search): add autocomplete endpoint (in progress)`

Bad: `cleanup`

Better: `refactor(utils): remove unused helper functions`

Bad: `bug fix`

Better: `fix(cart): correct tax calculation for international orders`

The pattern is clear: good commit messages tell you what changed and why. Bad commit messages tell you nothing.

Commit Message Best Practices

Follow these rules and your commit history will become a valuable asset instead of a liability.

1. Use the Imperative Mood

Write your subject line as if you're giving a command: “add feature” not “added feature” or “adds feature.”

Why? Git itself uses imperative mood in auto-generated messages (“Merge branch...”). It's the convention, and it reads cleanly in logs.

Good: `feat(api): add rate limiting to public endpoints`

Bad: `feat(api): added rate limiting to public endpoints`

2. Limit the Subject Line to 72 Characters

Git doesn't enforce a limit, but most tools (GitHub, GitLab, bitbucket) truncate longer subjects. Keep it concise.

If you need more space, use the body. The subject should be a summary, not the full story.

3. Separate Subject from Body with a Blank Line

Not all commits need a body, but when you include one, separate it from the subject with a blank line. This makes the commit message readable in both short and long formats.

```

fix(payment): handle expired credit cards gracefully

Previously, expired cards caused a 500 error. Now we catch the

Stripe error and return a user-friendly message asking for updated

payment information.

Fixes #890

```

4. Explain What and Why, Not How

The code shows how you made the change. The commit message should explain what you changed and why it matters.

Bad:

```

Changed the regex pattern in validateEmail function to use a different

character class for the domain part

```

Good:

```

fix(email): accept plus addressing in email validation

Updated email regex to support plus addressing ([email protected]).

Previously these valid emails were rejected during signup.

```

5. Reference Issues and Tickets

If your commit addresses a specific issue, reference it in the footer. Most issue trackers (GitHub, Jira, Linear) will automatically link commits to issues.

```

feat(search): add full-text search for product descriptions

Implements full-text search using PostgreSQL tsvector. Search results

now include products matching description text, not just titles.

Closes #456

```

Common Commit Message Mistakes (And How to Fix Them)

Mistake 1: Vague Messages

The Problem: “update”, “fix”, “changes”, “stuff”

The Fix: Be specific. What did you update? What did you fix?

Mistake 2: Multiple Unrelated Changes

The Problem: One commit with 15 files changed across different features

The Fix: Make small, focused commits. Each commit should do one thing.

If you've made multiple changes, use `git add -p` to stage specific hunks separately.

Mistake 3: No Context for Future Developers

The Problem: The commit message doesn't explain why the change was needed

The Fix: Imagine reading this commit 6 months from now. What would you need to know?

Mistake 4: Inconsistent Format

The Problem: Some commits use “feat:”, others use “Feature:”, others use nothing

The Fix: Adopt a standard format (like Conventional Commits) and enforce it with tools.

Mistake 5: Committing Broken Code

The Problem: “WIP” commits that break the build

The Fix: Use feature branches. Keep WIP commits local. Only push working code.

If you must commit work-in-progress, use a clear prefix: `WIP:` or `TEMP:` and make it obvious this isn't production-ready.

Automate Your Commit Messages

Writing good commit messages takes discipline. But you don't have to do it all manually.

AI-powered commit message generators can analyze your staged changes and generate clear, consistent messages following your team's conventions. You review and edit as needed, but the heavy lifting is done for you.

Benefits of AI Commit Generators

  • Consistency: Every message follows the same format
  • Speed: Generate messages in seconds, not minutes
  • Quality: AI suggests descriptive, specific messages
  • Learning: See examples of good messages as you work

Try It Yourself

The Git Commit Message Generator analyzes your staged changes and generates commit messages following Conventional Commits format. It's free, runs in your browser, and helps you maintain consistent, high-quality commit messages across your team.

No signup required. Just paste your `git diff` or let the tool generate it from your staged changes.

Related Articles

---

*Ready to write better commit messages? Try the Git Commit Message Generator and see the difference AI-assisted commits can make.*

Generate Better Commit Messages Automatically

AI-powered commit messages from your staged changes. Conventional Commits format, ready to commit.

Generate Commit Messages Now

More Articles