Git Best Practices for Developers

Chapter 1 · Practice 1 of 4

Make each commit one logical change

From Commits and commit messages

Why it matters

A commit is the unit you review, revert and search through later, so its size decides how useful your history is. Mixing a bug fix, a formatting pass and a new feature in one commit makes it hard to review, hard to revert, and useless for git bisect, which finds the commit that introduced a bug.

Rule: one commit does one thing.

  • Fix one bug
  • Add one feature step
  • Make one refactor

Commit when one small step works, not at the end of the day. Each commit on the main branch should build and pass tests on its own.

If you need the word "and" to describe a commit, it is probably two commits.

Do

  • Commit formatting changes separately from logic changes
  • Make sure each commit builds on its own

Avoid

  • Commits named wip, fix or changes on shared branches