Ctrl + K
Git7 min read

How Git Commits Should Be Written

Understand Git commit message conventions, recommended formats, common mistakes and best practices for maintaining a clean Git history.

Published: 2026-08-07

A Git commit message explains why a change was made and provides context for everyone who works with the repository. Well-written commit messages make project history easier to understand, simplify code reviews and help developers quickly identify when and why changes were introduced.

Although Git allows any commit message, following consistent conventions greatly improves collaboration, debugging and long-term project maintenance.

Why Commit Messages Matter

Git history is more than a record of code changes—it documents the evolution of a project. Clear commit messages allow developers to understand past decisions without reading every modified file.

  • Improve project history.
  • Simplify code reviews.
  • Help with debugging.
  • Support collaboration.
  • Enable automated tooling.

A Good Commit Message

An effective commit message is short, specific and describes what the commit accomplishes. It focuses on the change rather than the implementation details unless additional explanation is necessary.

Poor MessageBetter Message
updateFix login validation
changesAdd pagination to blog
bug fixPrevent duplicate form submission
workRefactor authentication middleware

Recommended Structure

Many projects use a short summary line followed by an optional blank line and a detailed explanation. The summary should describe the primary purpose of the commit in a concise way.

Short summary

Optional detailed explanation describing
why the change was necessary and any
important implementation notes.

Write in the Imperative Mood

Commit messages are commonly written in the imperative mood because they describe what applying the commit will do. This style keeps messages consistent across projects.

PreferredAvoid
Add user authenticationAdded user authentication
Fix broken linkFixed broken link
Remove unused codeRemoving unused code

Keep Commits Focused

Each commit should represent a single logical change whenever possible. Small, focused commits are easier to review, test, revert and understand than commits that combine unrelated modifications.

💡 Before committing, ask yourself whether someone reading the Git history six months later would immediately understand what the commit accomplished.
⚠️ Avoid generic commit messages such as 'update', 'fix', 'changes' or 'work'. These provide almost no useful information when reviewing project history.

The Conventional Commits Standard

Many software projects follow the Conventional Commits specification, which adds a structured prefix to commit messages. This makes commits easier to categorize and enables tools to automatically generate changelogs, release notes and semantic version numbers.

type(scope): short description

Examples:
feat(auth): add password reset
fix(api): handle empty responses
docs: update installation guide
refactor(ui): simplify sidebar component

Common Commit Types

TypePurpose
featIntroduce a new feature
fixResolve a bug
docsUpdate documentation
styleFormatting changes only
refactorImprove code without changing behavior
testAdd or update tests
choreMaintenance tasks

When to Add a Commit Body

Most commits only need a concise summary, but more complex changes can benefit from an additional description. The body explains why the change was made, highlights important implementation details or documents decisions that may not be obvious from the code itself.

Atomic Commits

An atomic commit contains one logical change. Instead of combining unrelated bug fixes, refactoring and new features into a single commit, separate them into smaller commits that each solve one problem.

Poor PracticeBetter Practice
One commit for many unrelated changesSeparate commits for each logical task
Feature and refactor togetherFeature first, refactor separately
Multiple bug fixes in one commitOne bug fix per commit when practical

Commit Message Length

The summary line should be concise while still describing the purpose of the commit. If additional explanation is needed, include it in the body rather than making the title excessively long.

Examples of Good Commit Messages

Add dark mode support

Fix memory leak in image loader

Update API documentation

Refactor user authentication service

Improve search performance

Remove deprecated utility functions

Benefits of Consistent Commit Messages

BenefitDescription
Readable historyMakes changes easier to understand
Faster code reviewsReviewers immediately know the purpose
Simpler debuggingHelps identify when issues were introduced
Automation supportEnables changelog and release note generation
💡 Write commit messages for future readers, not just for yourself. A clear summary today can save significant time when investigating project history months later.
⚠️ Avoid using commit messages as task lists or issue discussions. Keep them focused on describing the purpose and outcome of the code change.

Common Mistakes

Even experienced developers sometimes write commit messages that provide little context. Since commit history often serves as long-term project documentation, vague or inconsistent messages make debugging, reviewing changes and understanding past decisions much more difficult.

  • Using generic messages such as 'update', 'fix' or 'changes'.
  • Combining multiple unrelated changes into one commit.
  • Writing overly long summary lines.
  • Describing implementation details instead of the purpose of the change.
  • Using inconsistent commit styles across the project.
  • Skipping commit messages entirely when using automated tools.

Best Practices

  • Write concise, descriptive summaries.
  • Use the imperative mood (for example, 'Add', 'Fix' or 'Remove').
  • Keep commits focused on a single logical change.
  • Use Conventional Commits if your project follows the specification.
  • Include a commit body when additional context is helpful.
  • Maintain a consistent commit style across the entire repository.
💡 Imagine that another developer—or even your future self—will read the commit history months later without any additional context. A well-written commit message should explain the purpose of the change clearly enough that reviewing the code becomes much easier.
⚠️ Rewriting commit messages after they have been pushed to a shared branch may require rewriting Git history. Coordinate with your team before using commands such as git commit --amend or interactive rebase on commits that others may already have pulled.

Frequently Asked Questions

How long should a Git commit message be?

The summary should be short and descriptive, typically one concise sentence. If more explanation is needed, add a body below the summary rather than making the title excessively long.

What is the imperative mood in commit messages?

The imperative mood describes what applying the commit will do, using verbs such as 'Add', 'Fix', 'Remove' or 'Refactor'. This style is widely used because it creates consistent Git history.

What are Conventional Commits?

Conventional Commits are a standardized format that prefixes commit messages with types such as feat, fix, docs or refactor. They improve consistency and support automation tools that generate changelogs and release notes.

Should every commit include a detailed description?

No. Simple changes often require only a clear summary. A detailed body is most useful for complex changes, architectural decisions or modifications that need additional explanation.

Why are small commits recommended?

Small, focused commits are easier to review, test, debug and revert. They also produce a cleaner project history that is easier for developers to understand over time.

Helpful Git Tools

A Git Commit Generator helps create clear, descriptive commit messages, a Conventional Commit Generator formats commits according to the Conventional Commits specification, a Git Branch Name Generator suggests consistent branch names, a Changelog Generator builds project changelogs from commit history, and a Release Notes Generator converts commits into organized release summaries for software versions.

Conclusion

Well-written Git commit messages are an essential part of professional software development. They document the purpose of code changes, improve collaboration, simplify debugging and make project history significantly easier to navigate. By keeping commits focused, writing clear summaries, following consistent conventions and adopting standards such as Conventional Commits when appropriate, development teams can maintain a Git history that remains valuable throughout the lifetime of a project.