DEV Community

Cover image for How to Write Git Commit Messages Like a Pro
Silas
Silas

Posted on

How to Write Git Commit Messages Like a Pro

Ever wondered how to write commit messages for Git? Or maybe you’ve written messages that were technically correct but still caused murmurs in your team?

Well, that ends here and now. We’ve all been victims of this anomaly, and the way forward is simple: improve ourselves and share knowledge.
Let's dive in...

What is Git?

Git is a distributed version control system that manages versions of source code or data. Programmers often use it to collaborate on projects efficiently.

Git lets you work locally, track changes to files, and push those changes to remote repositories like GitHub or Bitbucket for collaboration.
More about git
Git official

How to commit

A commit is made by running git commit -m "some-message" with -m flag denoting message and "some-message" being the details of what you are committing, which is the main point of our article today.

Commit messages aren’t about long paragraphs, perfect grammar, or capitalization. They are about clarity, brevity, and readability.

Common Commit Message Tags

Using standard tags makes Git history clear and helps your team understand the purpose of each change.

  • feat:
    when the commit adds or changes functionality in a way that matters to users e.g feat: add GitHub OAuth login

  • fix:
    when the commit fixes a bug that existed e.g fix: handle API rate limits

  • docs:
    when only the documentation changes (no code behavior changes). e.g docs: update README with setup instructions

  • style:
    Code style or formatting changes that do not affect logic or behavior. e.g style: fix indentation

  • refactor:
    Code changes that improve structure or readability without changing behavior. e.g refactor: simplify GitHub client logic

  • test:
    Adds, updates, or fixes tests only. e.g test: add unit tests for login

  • chore:
    Maintenance tasks that don’t affect application behavior
    (dependencies, configs, scripts). e.g chore: update GitHub Actions workflow

  • revert:
    Reverts a previous commit e.g revert: undo login feature

  • perf:
    Changes that improve performance e.g perf: optimize database queries

  • build:
    Changes that affect the build system or external dependencies. e.g build: update dependencies

It is also good practice to write your commits in the present tense. Instead of "feat: added login functionality", do "feat: add login functionality"

"That's how dad did it, that's how America does it, and it's worked out pretty well so far"
~Iron Man 2008

This sets the base for linear and standard collaboration works and i hope you are a better commiter now that you've come this far.

Like my boss would say, leave with a quote to appear smart, i will leave you with this:

"Git commit messages are how we communicate to our future selves."

Happy committing, and may your Git history be forever clean and understandable.

Bye 👋

Top comments (0)