DEV Community

Cover image for OhSnap! Instantly Improve Your Git Commit Messages
Gedalya Krycer
Gedalya Krycer

Posted on • Updated on

OhSnap! Instantly Improve Your Git Commit Messages

The "OhSnap!" series explores bite-sized tips that you can apply today.

Sometimes becoming a better developer comes down to slight course corrections in our daily workflows.

Recently I came across this awesome article by, Chris Beams, that explains how to do that with an action we all perform — git commits.

The Tip

Write git commits imperatively, not as a description.

The Wrong Way

git commit -m "Added new page"

git commit -m "Fixed margin above the hero banner for a better layout"

git commit -m "This adds a new color"

The Right Way

git commit -m "Add About page"

git commit -m "Fix spacing above the hero banner"

git commit -m "Change headline color"

What is the difference?

The second versions are all actions. They sound abrupt, but they are meant to instruct what is about to happen, not describe why you did something.

Notice that even as imperative actions, they still communicate with specificity on exactly what was done.

At the end of the day, all we really want to know is what this commit will do to our main branch if merged. The body of the commit or a pull request can always hold the details of why you did something.

How do I write these correctly?

Chris Beams gives a fantastic sentence to test your commits against. If the sentence still makes sense afterwards, then it is a strong imperative commit.

If applied, this commit will your message here

git commit -m "If applied, this commit will Change headline color"


git commit -m "If applied, this commit will changes new color"

I highly encourage you to read the full article, as there are many more great tips in there.

Header image designed with Adobe Photoshop and Unsplash

Top comments (6)

iamshouvikmitra profile image
Shouvik Mitra

I use commitizen (conventional commits)

gedalyakrycer profile image
Gedalya Krycer

I just checked it out and it looks very cool. If anyone else is interested, this is their repo.

paulasantamaria profile image
Paula Santamaría

This is a great tip! Will definitely be using it from now on. I usually struggle trying to write short but meaningful commit messages and I especially have a hard time trying to decide which tense to use 😅

gedalyakrycer profile image
Gedalya Krycer

So glad you found it helpful! Yes, I was in the same boat before discovering this. Applied it to my last project and it made my commits way more consistent and meaningful. Happy coding!

marcelc63 profile image
Marcel Christianis

Really useful thanks!

gedalyakrycer profile image
Gedalya Krycer

Your welcome! Happy coding.