A Beginner’s Guide to Git — How to Write a Good Commit Message
Tags: git, beginners, codenewbie, tutorial
Published: 2020-03-24 14:08:44

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](https://herewecode.io/blog/a-beginners-guide-to-git-how-to-start-and-create-your-first-repository/).

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 last commits on Angular.js project on GitHub (a famous framework made by 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](https://herewecode.io/blog/content/images/2020/03/git-commits-history.png)Git commits history on Angular.js project [on GitHub](https://github.com/angular/angular.js/commits/master)

### 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 shortlist 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](https://herewecode.io/blog/content/images/2020/03/bad-git-commits.png)Bad git commits example from [Jason McCreary](https://jasonmccreary.me/articles/when-to-make-git-commit/)

> Note: If you want to have more example of bad commits and have fun at the same time, [a Twitter account named "gitlost"](https://twitter.com/gitlost) is tweeting every day with the funny and unfiltered commits.

- **BONUS - A changelog generation:** I’ll tell you a small secret, if you write good messages, you will be able to [generate a changelog](https://herewecode.io/blog/a-beginners-guide-to-git-what-is-a-changelog-and-how-to-generate-it/) directly from your commit messages. I share with you a few tools to do it: [Github Changelog Generator](https://github.com/github-changelog-generator/github-changelog-generator), [Git Chglog](https://github.com/git-chglog/git-chglog), [Auto Changelog](https://github.com/CookPete/auto-changelog), and [Conventional Changelog](https://github.com/conventional-changelog/conventional-changelog). Probably the next part of the series will be on this, if you want to be updated, [you can follow me on Twitter](https://twitter.com/gaelthomas_). I post every update there.

![Auto-generated Git changelog](https://herewecode.io/blog/content/images/2020/03/git-changelog.png)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](https://www.grammarly.com/), [Reverso](https://www.reverso.net/spell-checker/english-spelling-grammar/), or [GrammarCheck](https://www.grammarcheck.net/editor/). 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](http://udacity.github.io/git-styleguide/). There are a lot of others; a few of them are [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/), and [Angular Guideline](https://github.com/angular/angular/blob/master/CONTRIBUTING.md#commit). A commit guideline will help you to put an architecture 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'".

## Conclusion

I hope that you liked this guide on how to commit to Git! If you have any questions or feedback, feel free to ask.

If you have any other tips on how to make good commits, please let me know.

---

If you want more content like this, you can [follow me on Twitter](https://twitter.com/gaelgthomas/), where I tweet about web development, self-improvement, and my journey as a fullstack developer!