Like A Girl

Pushing the conversation on gender equality.

Code Like A Girl

Useful Tips for writing better Git commit messages

img src:

Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people. As a developer one of the basic tools we can’t escape using is making use of git for our workflow. One of the mistakes most developers make. Well this is technically not a mistake but you know the saying “ if you can do it better then why not”.

Some Rules to keep in mind when writing commit messages

  1. Separate subject from body with a blank line
  2. Limit the subject line to 50 characters
  3. Capitalize the subject line
  4. Do not end the subject line with a period
  5. Use the imperative mood in the subject line
  6. Wrap the body at 72 characters
  7. Use the body to explain what and why vs. how

Mistake 1: We tend to mash the subject of a commit message with the body: Writing a subject of a commit together with the body of that commit message is the wrong way to go. When you notice your commit message is getting too long to explain this means that commit is doing too many things break it down.

Doing this:

git commit -m "added new css styling for danger button in other to differentiate between the primary button and other button styles."

Instead of this:

git commit -m "Add new feature"

Mistake 2: Not limiting the subject to more than 50 chars: Always make sure the subject of commit never exceeds 50 characters it’s a general rule of thumb. Having more characters tends to get truncated by GitHub and what we are striving for is for a user to know what a commit is doing at one glance.

Mistake 3: Using lower case format for the subject of a commit

Doing this:

git commit -m "added new feature"

Instead of this:

git commit -m "Add new feature"

Mistake 4: Ending a subject line with a period: Always make sure you never end a subject with a period.

Doing this:

git commit -m "Modified codebase."

Instead of this:

git commit -m "Modify codebase"

Mistake 5: Not always using the imperative mood in the subject line: Every proper git commit should be in imperative mood. “what this means is simply a sentence that is written with action or command”.

A properly formed Git commit subject line should always be able to complete the following sentence:

  • If applied, this commit will your subject line here

For example:

  • If applied, this commit will "Add auth to X"

Notice how this doesn’t work for the other non-imperative forms:

  • If applied, this commit will "added auth to Y"

Mistake 6: Making a long note for body of commit message: Some commit messages requires more explanation especially when the subject line is vague. adding body to the commit comes handy in cases like this. Always strive to limit the number of char in the body to 72 char. let your body explain what the commit is doing and why it is doing it.

Mistake 7: Use the body to explain what and why vs. how: Like i explained in #6 above always make sure the body of your commit explains what and why the commit is doing exactly. explain why the change is necessary, and what side effect does it have. Instead of describing how you solved the problem.

Some useful resources for more explanation.

Thanks for reading. Hope you learnt from these tips. A few lame git jokes for you enjoy.

Why did the commit cross the rebase? To git to the other repo

In case of fire: git commit, git push, leave the building