Commit Message Style in Git


Following best practices for commit messages in Git, such as writing concise and imperative statements while explaining changes, helps maintain a clear and structured change history for better collaboration and project management

Published on October 11, 2024 by Roman Surkoff

git post commit codestyle best-practice

2 min READ

Maintaining a clear and structured change history in Git is essential for effective version control, and following best practices for commit messages can greatly enhance this process. Key guidelines include writing concise messages in the imperative mood, explaining the reasons for changes, and separating messages into a clear header and body. By grouping related changes and regularly reviewing the commit history, you can ensure better organization and collaboration within your projects.


Commit Message Style in Git

Working with Git is not only about version control, but also about maintaining a change history that can be clear and structured. Below are best practices for writing commit messages:

1. Write a clear and concise message The commit message should be clear and explain the essence of the change. For example:

git commit -m "Fixed button display on the homepage"

2. Use the imperative mood Phrase commit messages in the imperative mood. This helps create consistency in the history. Example:

git commit -m "Add date filtering capability"

3. Indicate the reason for changes A good practice is to briefly explain why you made the change. For example:

git commit -m "Optimize image loading for better performance"

4. Separate messages into a header and body Use a header of up to 50 characters, and then add a more detailed description after a blank line. Example:


git commit -m "Update library dependencies"

Updated libraries to the latest versions for improved security and performance.

5. Group related changes Avoid creating too many small commits. Try to combine logically related changes into one commit:

git commit -m "Add new functionality: upload and delete files"

6. Avoid using timestamps Do not include time or date in messages, as this is already recorded in the commit itself. Instead, it is better to specify what was changed:

git commit -m "Fix bug in message sending function"

7. Check the commit history Regularly review the commit history using the command:

git log --oneline

This will help you maintain order and structure in your project.

Conclusion By following these simple rules, you will be able to create a clear and accessible change history in your project, making work easier for both you and your colleagues. 👍