Igor Khromov blog

What are best practices to write git messages when commit?

Here are some best practices to write git commit messages:

  1. Keep it concise: Keep the commit message short and to the point, while still providing enough information to understand the change. A good rule of thumb is to limit the message to 50 characters or less.
  2. Use the imperative mood: Write the commit message in the imperative mood, as if you are giving a command. For example, use “Fix bug” instead of “Fixed bug” or “Fixes bug”.
  3. Start with a capital letter: Start the commit message with a capital letter, as if it is the beginning of a sentence.
  4. Use the present tense: Write the commit message in the present tense, as if you are describing the current state of the code. For example, use “Add feature” instead of “Added feature”.
  5. Provide context: Provide context for the change in the commit message, such as the motivation behind the change or the problem it solves. This can help in understanding the change in the future.
  6. Separate subject and body: Separate the subject of the commit message from the body with a blank line. Use the subject to summarize the change and the body to provide more details.
  7. Use bullet points in the body: Use bullet points in the body of the commit message to break up longer explanations into digestible pieces.
  8. Reference related issues: Reference related issues in the commit message, using the issue tracker ID or URL. For example, use “Fix #1234” or “Fix https://github.com/user/repo/issues/1234” to reference issue #1234.
  9. Use tags: Use tags in the commit message to indicate the type of change, such as “feat” for a new feature, “fix” for a bug fix, “refactor” for a code refactoring, or “docs” for documentation changes.
  10. Review before committing: Review the commit message before committing, to ensure it accurately reflects the change and follows the best practices for commit messages.

Following these best practices can help make your commit messages more readable, informative, and useful for future development and collaboration.