OhSnap! Instantly Improve Your Git Commit Messages
Gedalya Krycer
Posted on January 18, 2021
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"
vs.
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
Posted on January 18, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.