Recently I published a Simply Explained article that worked to expand on some context I felt was missing from the web. This article did so well on Dev.to that I wanted to extend the series!
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 you made to your project. It is greatly important to learn how to make a good commit message no matter if it is a personal or professional project.
I do have to give credit to my coding boot camp instructor for teaching me how to write good commit messages. He made me 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 than saving everything to one commit or a poor commit sentence. Since then, I always spend a few extra minutes to make sure I have a good commit.
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 easily be 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.
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 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 and a beginner.
The best way to learn how to code is by not 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.
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 to COMMIT EARLY, COMMIT OFTEN. Start your commit every time you fix a bug, console log your data, style your components, etc. It is very important to have viable commits. My favorite tool for this is GitKraken as it is a GUI that splits up your commits.
It took me months before I started putting emojis on my commit messages. However, I have since realized how much adding an emoji can benefit commit messages. It has made my commit messages easy to grasp, understandable, and cleaner. The best emoji to use is one that is related to your commit message such as 🐛 for a bug fix or 💄 for styling your components. 🔖Click this for a cheat sheet on the best emoji to use for commit messages.
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.
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.
Commit messages are not difficult to make. Using these three ingredients, you can make excellent commit messages that are clean and easy to understand. Below is an example of a good commit.👇