DEV Community

Cover image for Simply Explained: Git Commit Message
Shawn Humphreys
Shawn Humphreys

Posted on

Simply Explained: Git Commit Message

Are you guilty of bad commit messages?๐Ÿ˜ฎ 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!๐Ÿ‘‡

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!

๐Ÿ“‡Table of Contents

What is a commit messageโ“

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. 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?๐Ÿ™‹

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

Most of us have been guilty of writing bad commit messages just because "I know what this message means"๐Ÿ’…. 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"๐Ÿ™…? 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?๐Ÿ’

Commit message humor

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 as it is a GUI to split up your commits.

The Three Ingredients๐Ÿ”ฅ

Commit message example

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 ๐Ÿ› for a bug fix or ๐Ÿ’„ for styling your components. ๐Ÿ”–Click this for a cheat sheet on best emoji to use for commit messages.

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๐ŸŽฅ

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.๐Ÿ‘‡

Alt Text

Thank You

If this article provided any value to you, please leave a โค๏ธ 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!

mrshawnhum image

Latest comments (0)