Git Commit is referred to the act of submiting your code and versioning it in the Git repository for future reference. In more simpler terms, it's like adding a checkpoint which you can refer later.
Using git commit has many benefits such as:
To commit your changes to git, you can use the below command:
git commit -m "your commit message"
Replace "your commit message" with the actual message you want to use. You can add a relevant title here mentioning the change or feature being submitted as part of this commit.
Before committing your changes, we need to ensure that the changes are staged first. Otherwise you may get an error mentioning "no changes to commit...".
If you want to stage and commit all the files in one go. Then you can skip that extra staging step by using this shortcut command:
git commit -a -m "second commit without staging"
This will automatically stage all the tracked files and commit them to the repo with the given commit message. All the interim steps will be executed in one go.
A point to remember is that this command will only work for the files which are already being tracked, i.e. the files which were earlier committed atleast once. If you just created a new file which is yet to be commited for the first time, then it will be skipped. For those new files you may be required to stage them first before commiting.
In the earlier commands, the commit message spanned across just one single line. What if you want to add a longer description? That's when you can make use of multi-line comments by using this command:
git commit
Yes, that's it. No commit message...
You may ask, then where do I add the commit message?
When you run that command, an editor will open up on your terminal with some pre-written messages (which are commented using # keywords) like this:
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch master
# Changes to be committed:
# modified: file.txt
#
~
~
~
~
You can just add your commit message there without using the # key (as that will ignore the commit message).
If the editor opens in your terminal, it might be in read only mode initially. You just have to press "INSERT" button to make it editable. Once you are done adding the commit messages in multiple lines, click on the "Escape" button on your keyboard, and then press the key combination ":wq" to perform the commit action.
If you want to view the history of recent few commits, then you can use this command:
git log
Once you enter this command you will see the meta data of the recent commmits like this:
commit d222919719b2e72016510ec479f96236c642a38d (HEAD -> master)
Author: Your name
Date: Fri Apr 3 11:23:48 2026 +0530
My third commit
commit e49e9aca74e111f8413633cb6ba3ee2b051f6386
Author: Your name
Date: Fri Apr 3 09:14:33 2026 +0530
My commit message line 2
My commit message line 3
My commit message line 4
commit e19139d29d7798aa4847b1896d970f20bf7a7576
Author: Your name
Date: Fri Apr 3 09:09:11 2026 +0530
:
You can scroll through the list for older commits by using the down arrow key on your keyboard. Once you are done, you can enter the ":wq" key combination to exit the logs.
That's all for this tutorial, I hope you liked reading this tutorial. Do share this among your friends or colleagues.
Fully customizable CRM Software for Freelancers and Small Businesses