DEV Community

Cover image for What Makes a Good Git Commit?
Soumyajit Mukherjee
Soumyajit Mukherjee

Posted on

What Makes a Good Git Commit?

Git commits are more than checkpoints.

They form a historical record of how a project evolved.

Unfortunately, many repositories contain commits like:

update
fix
changes
final
final2
please work
Enter fullscreen mode Exit fullscreen mode

These messages aren't very useful.

A Better Commit

Instead of:

fixed stuff
Enter fullscreen mode Exit fullscreen mode

write:

Fix duplicate order creation during checkout
Enter fullscreen mode Exit fullscreen mode

A good commit should communicate the purpose of the change.

Keep Commits Focused

A commit like:

Add authentication
Enter fullscreen mode Exit fullscreen mode

might include:

  • Login
  • Registration
  • Password reset
  • UI redesign
  • Database migration
  • Random formatting changes That's difficult to review.

Instead, separate logical changes when possible.

Why Small Commits Help

Focused commits make it easier to:

  • Review code
  • Revert changes
  • Find bugs
  • Understand history
  • Cherry-pick changes
  • Debug regressions

Conventional Commits

Some teams use a convention such as:

feat: add password reset flow
fix: prevent duplicate payments
docs: update installation guide
refactor: simplify user service
test: add order validation tests
Enter fullscreen mode Exit fullscreen mode

This creates predictable history.

Commit Messages Should Explain Why

This:

Update payment service
Enter fullscreen mode Exit fullscreen mode

is vague.

This is better:

Retry failed payment requests after temporary gateway errors
Enter fullscreen mode Exit fullscreen mode

The second message tells future developers what changed and why it matters.

Final Thoughts

Your Git history is documentation.

Write commits as if someone will need to understand them six months from now.

Top comments (0)