DEV Community


Level Up Your Commit Messages With These Tips!

Akash Shyam
UI/UX Designer | MERN Stack Developer | Freelancer
・2 min read

At some point, we’ve all come across a commit message we don’t understand. Let’s rectify that commit by commit:

1. Specify the type of comment

  • feat: for feature addition
  • fix: for bug fixes
  • refactor: for changing the way a code block is written without changing the final result
  • style: for style changes(CSS/Sass etc)
  • test: anything and everything about testing
  • docs: documentation addition/updates
  • chore: code maintenance

Do not restrict yourself to these types, feel free to add more types of comments but be consistent across the code base.

2. Never assume another developer understands the original problem i.e. the reason for the commit

I recently started working on an existing codebase along with 3 developers. Me and another dev just started working on the codebase. On the second day, when I woke up to pull the latest code to my database I see this:

fix: bug inside the StudentList screen regarding the list
// … some irrelevant details about the new solution
Enter fullscreen mode Exit fullscreen mode

When I looked at it, I had no idea what the problem was. After about 15 minutes of chatting back and forth, I finally understood the original problem.

Just a single paragraph, that’s all I ask. One paragraph describing the problem containing 2–3 lines. It will help you too in the future, when you come back later trying to fix a bug.

3. Limit the subject line to 50 characters

50 characters is not a hard limit, just a rule of thumb. Keeping subject lines at this length ensures that they are readable, and forces the author to think for a moment about the most concise way to explain what’s going on.

Github will truncate commit messages over 72 characters

Checkout the remaining article here. I've saved the best for the last!

Discussion (4)

akashshyam profile image
Akash Shyam Author

Don't forget to check the remaining article here . It contains 4 more tips!

karanpratapsingh profile image
Karan Pratap Singh

Hey this is a great tip, I suggest adding conventional commits as well

akashshyam profile image
Akash Shyam Author

I actually have including some portions from the conventional commits page.

karanpratapsingh profile image
Karan Pratap Singh

Oh nice, thanks