Simply Explained: Git Commit Message
Tags: codenewbie, beginners, git, github
Published: 2020-08-01 00:25:04

Are you guilty of bad commit messages?:open_mouth: I recently stumbled across a post on Dev.to that was very valuable(and others think so too as it was the top 5 post of the week it was published). The author was straight to the point and very informative. Check out the article below!:point_down:

{% link https://dev.to/chrissiemhrk/git-commit-message-5e21 %}

Although the author did an excellent job, there was some context missing that would be beneficial. The previous Simply Explained article did so well that I wanted to extend the series!  

### :card_index:Table of Contents
* [What is commit message:question:](#what)
* [Why are commit messages important?:raising_hand:](#why)
* [How to make good commit messages?:information_desk_person:](#how)
* [Examples of a good commit.:movie_camera:](#example)
* [Thank you!:smiley:](#thanks)

## What is a commit message:question:<a name="what"></a>

If you use Git/GitHub as your version control and understand the basics, you might have already heard of commit messages. [If you are new to GitHub, click here to understand the basics](https://guides.github.com/activities/hello-world/). A commit in GitHub is described as a saved change. A commit message explains what change did you perform to your project. It is greatly important to learn how to make a good commit message rather it is a personal or professional project.


## Why are commit messages important?:raising_hand:<a name="why"></a>

I do have to give credit to my coding boot camp instructor for teaching me how to write good commit messages. He made it well aware of the importance of a well-structured commit message. During my time at my coding boot camp, I was corrected each time I had a bad commit message rather it is saving everything to one commit or poor commit sentence. Since then, I will always spend an extra few minutes to make sure I have a good commit. 

#### 1. Easily obtainable for other projects

Have you ever encountered a bug that you had fixed in the past, but can't remember how? Have you ever had a project that you were working on and realized that you built this component before? A good commit message can be easily found when you need it later. You can develop a pattern to easily find it and see what you did to duplicate what you need.

#### 2. Easily understandable for other developers

![Alt Text](https://media.giphy.com/media/zXA5VEmXr7OUg/giphy.gif)

Most of us have been guilty of writing bad commit messages just because "I know what this message means":nail_care:. That is great that you understand the commit message, but what if you are reaching out for assistance from other developers and they have a hard time understanding what the process you took because you saved 80% of your project under one commit called "stuff working":no_good:? This is especially troublesome when you are working professionally with a team of developers or contributing to open-source projects. A good commit message could be the difference between a knowledgeable developer to a beginner.

#### 3. Great way to learn!

The best way to learn how to code is not by remembering everything, but by understanding what you are coding. The best way to write your commit message is to make it about what your code is achieving. 

## How to make good commit messages?:information_desk_person:<a name="how"></a>

![Commit message humor](https://dev-to-uploads.s3.amazonaws.com/i/s0rqzqt96g5l00f6sq2l.jpg)

You understand why commit messages are important, but how exactly do you make good commit messages? It does not have to be difficult to write good commit messages. The most important rule to learn is **COMMIT EARLY, COMMIT OFTEN**. Start your commit every time you fix a bug, console log your data, style your components, etc. This is very important to have viable commits. My favorite tool for this is [GitKraken](https://www.gitkraken.com/git-client) as it is a GUI to split up your commits.

### The Three Ingredients:fire:

![Commit message example](https://dev-to-uploads.s3.amazonaws.com/i/tioq31glypc2os7o1b4r.png)

#### 1. Emoji

It took me months before I started putting emoji on my commit messages. However, I realized how much of a benefit it was adding an emoji to commit messages. It has made my commit messages quickly-grasped, understandable, and cleaner. The best emoji to use is what is related to your commit message such as :bug: for a bug fix or :lipstick: for styling your components. [:bookmark:Click this for a cheat sheet on best emoji to use for commit messages.](https://gitmoji.carloscuesta.me/)

#### 2. Verb

The next ingredient is to add an imperative verb to your message. Good examples are "Add", "Fix", "Restructure", etc. **Never add "-ed" or "-ing" to your message like "Added" or "Adding".** Your verb should start with a capital letter as well.

#### 3. Object

What are you fixing? What are you styling? What did you add? unless necessary, this should be stated in one or two words such as "components", "home page", "images", etc. 

## Examples of a good commit:movie_camera:<a name="example"></a>

Commit messages are not difficult to make. Using the three ingredients, You can make excellent commit messages that are clean and easily understandable. Below is an example of a good commit.:point_down:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/tn60t35m9dw33epob50h.jpg)

## Thank You<a name="thanks"></a>

If this article provided any value to you, please leave a :heart: or let me know your thoughts! Follow me to keep up when I post more articles as I will be posting five days a week until further notice. Let me know what other topics I can simply explain to you!

{% user mrshawnhum %}