Git

How to Write a Good Git Commit Message – Best Practices

While working on the Git repository, users may need to update all changes they have made in the project source code or folder. It is the easiest way to notify Git about the added changes using the commit command along with a short message to differentiate every committed change. To attach the commit message, a specific flag can also be utilized with the commit command.

This blog will talk about:

Let’s move ahead toward the mentioned steps.

Best Practices for Writing a Good Git Commit Message

To write a good Git commit message, there are a few things that users should keep in mind:

  • Don’t use a punctuation mark at the end of the message.
  • Cross-check spelling after writing.
  • Avoid unnecessary capitalization.

How to Commit Changes?

To commit changes in Git local repository, firstly, we will move to the Git local repository. After doing so, create and add a new file to the required repository. After that, update the repository by committing the changes.

Now, we will practically implement the given procedure.

Step 1: Move to Git Repository

First, move to the desired Git repository using the “cd” command:

$ cd "C:\Users\nazma\Git\Comments"

Step 2: Create New File

Run the “touch” command to create a new file:

$ touch file1.txt

Step 3: Track New File

Now, track a new file by utilizing “git add” command:

$ git add file1.txt

Step 4: Update to Repository

Next, type out the “git commit” command with the “-m” option to update the repository by committing the added changes:

$ git commit -m "new file added"

We have explained the procedure of writing a good commit message both theoretically and practically.

Conclusion

Best practices to write a Good Commit message are: Don’t use a punctuation mark at the message end, Cross-check spelling, and avoid unnecessary capitalization. For the purpose of committing changes to the Git local repository, firstly, move to the local repository. Then, create and add a new file to the required repository. After that, update the repository by committing the changes. This blog discussed and applied the best practices for writing a good commit message.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.