Maintain a Clean Commit History

Learn to commit only what’s relevant and clean the rest of the changes.

Before we commit, we may want to clean the commit to only keep what’s relevant.

The git add workflow

Here’s a typical git add workflow that contains a reveal and double-check process to ensure that only the changes we want to commit are added.

  1. Run git status to see what has changed since the last commit. Review the list to check if all changes are for the same purpose.

  2. Run git add . if all the changes are for one purpose. Otherwise, run git add <folder/file> to separate different files/folders into different commits according to their purpose.

  3. Run git status to reveal the added (staged) changes. These are the changes that will be committed.

  4. Run git commit -m to commit the change with a one-line comment. Or run git commit and write a long message if it’s a crucial commit.

  5. Repeat the steps 1 through 4 until all changes are committed.

Get hands-on with 1200+ tech skills courses.