How to create a git commit with a message

We can use the git commit command to save our changes to the local repository. We use the git commit command with the option -m to create a git commit with a message.

Creating a git commit with a message is a good practice that helps describe and share our changes with other developers.

Syntax

To create a git commit with a message, use the git commit command with the -m option as shown below:

git commit -m "message"

It is a good practice to keep the length of the "message" below 50 characters.

Why do we need it?

Most of the time, we do not work alone on our projects. Instead, there is a team of developers working together. We must create a git commit with a message to explain to other developers precisely what changes have been made in the project and why these changes were necessary.

Why do we need to add a message to a git commit?

Code

Consider the code snippet below, where we create a git commit with a message.

git rm file1.txt
git commit -m "file1.txt removed from working directory"

Explanation

The code snippet above removes the file file1.txt from the working directory using rm command. We save the changes of the removed file to the local repository using the git commit with option -m in line 3.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved