Skip to main content
  1. Learn
  2. Software Development
  3. Guides
  4. Git tutorial
  5. Git basics
  6. Recording changes
  7. Git commit messages
GuidesSoftware DevelopmentBacklog
Git

Project and code management together.

Git commit messages

When committing your changes, you are required to enter a commit message. Git commit messages play a crucial role in communicating the context and intent behind changes made to a project.

The commit message should concisely and accurately describe the changes you’re making. To make messages consistent and easy to understand, try the following Git commit message template:

  • Line 1: Abstract of the contents changed by commits
  • Line 2: Blank line
  • Line 3: Reason for changes

Git commit messages: best-practices

A well-crafted commit message enhances clarity, collaboration, and project maintainability. Here are some best practices for writing effective Git commit messages:

  1. Use a clear and concise summary: The first line of the commit message should succinctly summarize the change.

    Example: "Add user authentication feature"

  2. Provide context and details: Use the body of the commit message to provide additional context, if necessary.

    Example: "This commit introduces a new user authentication system using JWT tokens for secure access."

  3. Separate subject from body with a blank line: Use a blank line between the subject line and the body to improve readability.

    Example:

    Add user authentication feature

    This commit introduces a new user authentication system using JWT tokens for secure access.

  4. Use imperative mood: Start the subject line with an imperative verb (e.g., "Add," "Fix," "Update").

    Example: "Fix typo in README"

  5. Keep subject lines 50 characters or less: Limit the subject line to around 50 characters to ensure it is readable in Git log and various tools.

    Example: "Update login form validation"

  6. Capitalize the subject line: Start the subject line with a capital letter.

    Example: "Refactor database connection handling"

  7. Use bullet points in the body for complex changes: For complex changes, use bullet points in the body to list key aspects or details of the commit.

    Example:

    Add user authentication feature

    • Introduce JWT tokens for secure user login
    • Implement password hashing for user credentials
    • Enhance error handling for authentication failures
  8. Reference relevant issues: If the commit relates to a specific issue or task, reference it in the commit message body using a keyword like "Fixes" or "Closes."

    Example: "Fixes #123: Resolve issue with user registration form"

  9. Write in the present tense for the subject line, past tense for the body: Subject line verbs should be in the present tense (e.g., "Add," "Fix"), while body descriptions should be in the past tense (e.g., "Added", "Fixed").

    Example of a good commit message:

    Refactor authentication middleware

    • Replace deprecated libraries with updated authentication middleware.
    • Enhance security by implementing CSRF token validation.
    • Simplify error handling and improve logging.

By following these best practices, you can ensure that your commit messages contribute to a well-documented and easily navigable project history.

Subscribe to our newsletter

Learn with Nulab to bring your best ideas to life