How to Write Good Commit Messages in GitHub?
Version control or source control is the practice of keeping track of changes that you had made to software code. Version control systems are the tools that help software teams manage changes to their source code. Version control software keeps track of every modification that you made to the code in a special kind of database. Version control software is the most important part of modern software developer practices. There are many version control software available in the market but the most commonly used version control software is Git.
In Git, we use the commit command to save changes to our repository after staging. In other words, git commit creates a commit, which is like a snapshot of your entire repository at a specific time. When you make a commit you have to add a commit message to it so that it can help you to identify a specific commit whenever there is a need of it in the future.
How to write a commit message with Git?
There are two methods to write a commit message:
It is used when you have to add a lengthy description but it is not commonly used when we have to add a short commit message.
To use this method, run the command git commit without option and it will open the default text editor. In the editor which has been opened the first line is the subject which gives a short description about the commit and then leaves a blank line after it and everything after the blank line would be an extended description. You can also change your default editor according to your choice.The syntax for the editor method is given below –
So this command will open your default editor where you can add a subject and short description about that commit. You can add the subject and body of the commit in the following manner:
It is the most commonly used method where you can add a commit message with the git commit command in a single line.
The syntax for command line method is given below –
git commit -m “subject” -m “description..”
Here the first and second -m option is subject and description respectively.Why should we write good commit messages?
Whether you are working on a personal project or a team project, it is necessary to write a good commit message because it is the only way to communicate context about a change to your teammate or to other developers who are making a contribution to your project. Good commit messages can also help you to understand easily why you made some changes in the past. Good commit messages can develop a great understanding that can make development and collaboration more efficient.
How to write good commit messages?
There are many conventions followed by different developers and teams to write a commit message but there are many tips that can help you to follow a better convention to write commit messages.
Here are some of the tips that can help you to write good commit messages-
Indicate the type of commit in the subject of commit messages. You should specify the commit type on the basis of changes that you had made. For example, if you had made changes to documentation, then you should specify it your commit in the following manner –
git commit -m “docs updated ABC”
In the above-given commit message ‘docs’ shows the type of commit or shows that changes are made in the documentation. Similarly, you can use ‘fix’ for bug fix, ‘style’ for updates related to styling, and ‘test’ for testing related things.
Don’t use unnecessary punctuation marks. Some developers use punctuation marks in the commit messages, this is not a good practice because sometimes it may look very unprofessional or ugly. For example, many developers don’t pay attention to writing proper commit messages, and they just add a random text with lots of punctuation marks. You can have a look on such types of commit messages given below:
git commit -m “added—!–!–Readme!!”
You can notice that in the above-given commit message, we have used tons of punctuation marks and this makes the commit message more ugly and confusing. So, try to put your commit messages punctuation marks free.
Use capitalization for the subject and description. It is not necessary to use capitalization but it is generally a good practice.
Add a description to explain what changes you have made and why you made them
Do not assume that the reviewer will understand what the original problem was, ensure that you add it in the commit message
Make use of imperative mood in the subject
Follow the convention defined by your team
The most important thing about a commit message is that it should be clear and meaningful. Writing good commit messages shows how active a contributor you are.