Embark on my indie hacking journey: Documenting each step, sharing insights along the way

Home » Blog » A Beginner’s Guide to Git — How to Write a Good Commit Message

A Beginner’s Guide to Git — How to Write a Good Commit Message

You are a developer, and you started to use Git recently? If you are wondering what the best way to create a good commit message for your project is, then this article is made for you.

After a few weeks without writing new articles, I’m coming back today with the next part of one of my most searched posts on Google.

When I started to write, one year ago, I created an article on how to start and create your first repository with Git.

This article is appreciated by the community and helps many people each week. Thus, the next part of this series will be how to write a good commit message.

What is a good commit message?

As a short reminder, the commit message is the short text you left when you save your work on Git. This message has the specific goal of identifying your work.

Just by reading it, anyone will be able to clearly understand what you did in this part of your work.

A good commit example

Below, you can find an example of the latest commits on GitHub for AngularJS, a popular framework developed by engineers at Google. As you can see, messages are clear, and we can better understand which work has been done in different parts.

For example, on July 24, 2019, “gkalpak” upgraded “SauceConnect” and switched to the last version of Safari (web browser).

Git commits history of Angular.js GitHub repository

Why is everyone not committing the same way?

Unfortunately, commits do not have a universal way to be written. Each project and each company define specific rules for their needs.

Don’t worry; you will often find similar ways of writing the message.

Although, I highly recommend you to read the rules before starting in a company or working on an open-source project.

I will give you more details on these guidelines later in this article.

Why is it essential to write your commit well

I created a short list of the advantages of using a good commit message.

  • A better collaboration: If you are working in a company, on an open-source project, it’s essential to follow the rules for better cooperation. If you write something understandable, following the rules of the project, the other developers will be able to work more efficiently, and they will not be required to ask you questions about your work.
Note: If you are working on a personal project, I highly recommend you to follow specific rules. It will improve your productivity, and if you ask help from another developer, it will be easier for him to start working on your project.
  • A better understanding: You need to create clear and understandable messages; it will help you and your collaborator to work on a project. Below, you can find an example of a git commit history with only unclear messages. As you can see, it’s difficult to understand what is made.
Bad git commits example example from Jasonc McCreary
Note: If you want to have more example of bad commits and have fun at the same time, a Twitter account named "gitlost" is tweeting every day with the funny and unfiltered commits.
Example of auto-generated Git changelog

How to write a commit message

If you want to write a good commit message, you need to follow some rules. I created a checklist below. Every time you want to commit, take the time to refer to this list.

  • Always check your grammar. It’s never pleasant to read a message full of errors. To do this, I recommend you to use a grammar tool. If you are writing in English, you can use Grammarly, Reverso, or GrammarCheck. These tools are not perfect, but they will remove most of your errors.
  • One commit, one change. Try to commit often. The ideal is to have each change in a different commit. It will be easier for you to go back to previous work.
  • Be clear. When you are writing a commit, try to be as transparent as possible. I recommend you to use simple English to go straight to the point.
  • Details what you did. Take the time to reread your code to write what you did. In the case you need to detail a lot, I recommend you to use the description part of the commit.
ADDITIONAL INFORMATION: I want to share with you more details on the 'git commit' command. If you are not using a git software, you should know that you can create detailed commit by typing this command:
git commit -m "Title" -m "Description"

It’s the same as before, but with a second part for the description. So, -m 'title' is to write the short title of the commit, and -m 'description' is to write the description if you need to give more details.

  • Use a git guideline. If you want to have a clear git commit history, I recommend you to follow a guideline. It’s a guide of how to commit. In my case, I choose this simple one from Udacity. There are a lot of others; a few of them are Conventional Commits, and Angular Guideline. A commit guideline will help you to put a structure to your commit. For example, put a tag to clarify what you did: git commit -m "fix: correctly delete all user information when the button delete account is triggered".

Thanks for reading. Let’s connect!

➡️ I help you grow into Web Development, and I share my journey as a Nomad Software Engineer. Join me on Twitter for more. 🚀🎒

Gaël Thomas

Getting started on a solopreneur journey alongside my 9-5 🚧 Documenting my learnings and progress on Twitter (X) ✍️ Software Engineer 💻 My latest project: BooksByMood 📚

Post navigation