User Avatar

Senior Software Engineer | I help web developers to learn Next.js | 10+ years industry experience

3 Best Practices For Git Commits That Every Software Developer Should Obey So They Can Fix Bugs Easier, Appear Professional And Get Faster PR Reviews

Git commits are not a trendy subject, but they are in the core of anything you do as a software developer.

I first used Git in 2008. Since then I've worked on hundreds of projects that use it. Over the years I've developed a set of best practices that I follow regarding Git commits.

If you follow them, they will make your colleagues like you even more, enable you to solve bugs faster & easier, and get reviews for your PR more easily.

#1: Commit Regularly

You should commit rather too much than too little.

This ensures that there aren't big 100+ files modified per commit and anyone reading the commit history can get a better understanding what has happened.

Committing regularly ensures that changes to your repo are incremental and manageable.

#2: Write Meaningful Commit Messages

Writing good commit messages is integral for others (and yourself!) to understand what has happened in the commit.

  • Clarify the intent of changes

  • Be concise and descriptive

  • Don't write: "Bugfixes" - instead write: "Fix bug that displayed wrong price for the product after logout."

  • Use imperative mood - "Fix" instead of "Fixed" or "Change" instead of "Changed"

Adopting these practices for your commit messages makes your commit history a bliss to read.

#3: Commit Logical Changes (Even If They Are Simple)

Use atomic commits.

This means that we make one commit per one particular change. The changes can be to multiple files but the changes as a whole should represent a logical change.

Doing this makes makes it easier to understand and debug the commit history.