WalzoneInterview Prep
📞 Interviewing soon? Practice with a realistic AI mock phone interview — it calls you, then scores you. First 15 min FREE →

Git · Basic · question 20 of 100

What are the best practices for writing a good commit message?

📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

Writing a good commit message is important for making it easy to understand the changes made in a commit and to provide context for other developers who may be working on the same project. Here are some best practices for writing a good commit message in Git:

Keep the message concise and descriptive: A commit message should be brief but informative. It should describe the changes made in the commit in a way that is easy to understand.

Use the imperative mood: A commit message should be written in the imperative mood, which means it should be written as if giving a command. For example, instead of saying "Changed the file," say "Change the file."

Separate the subject from the body: A commit message should be divided into two parts: a subject and a body. The subject should be a short summary of the changes made in the commit, while the body should provide more details about the changes.

Provide context: A commit message should provide context for the changes made in the commit. This can include information about why the changes were made, what problem they solved, or any relevant information about the project or feature being worked on.

Use the present tense: A commit message should be written in the present tense, as if describing the changes being made at the time of the commit. For example, instead of saying "Changed the file," say "Change the file."

Here’s an example of a good commit message:

    Add feature to sort list of items

This commit adds a new feature to sort a list of items by name or date. The feature is accessed through the context menu by right-clicking on a list item. Sorting is performed using a stable sorting algorithm to ensure that items with the same name or date remain in their original order.

In summary, writing a good commit message in Git involves keeping the message concise and descriptive, using the imperative mood, separating the subject from the body, providing context, and using the present tense. Following these best practices can make it easier to understand the changes made in a commit and to provide context for other developers working on the project.

Reading is step one. Saying it out loud is the interview. Our AI interviewer calls your phone and runs a realistic Git interview — then scores it.
📞 Practice Git — free 15 min
📕 Buy this interview preparation book: 100 Git questions & answers — PDF + EPUB for $5

All 100 Git questions · All topics