Skip to Main Content

Git and GitHub

This guide is meant to provide basic information and access to resources on Git and GitHub.

Writing Good Commit Messages in GitHub and GitHub Desktop

Clear, concise commit messages are essential for maintaining a well-organized project history. Follow these best practices when creating commit messages:

  1. Keep It Short and Descriptive
    Aim for a short subject line of around 50 characters that clearly summarizes the change. Example:
    Update README to reflect new installation instructions

  2. Use Imperative Mood
    Write the message as if giving a command:
    Fix typo in user documentation
    Instead of: Fixed typo in user documentation.

  3. Capitalize the Subject Line
    Always capitalize the first letter of your subject.
    Refactor authentication logic

  4. Skip the Period
    There’s no need for punctuation at the end of the subject line.
    Correct: Improve error handling for login API
    Incorrect: Improve error handling for login API.

  5. Use the Description Field for Details (Optional)
    If the commit is complex, add a brief explanation of the 'why' in the description or body of the message. Leave a blank line between the subject and body.
    Example:
    Subject: Refactor database schema for better performance
    Description:
    Refactored schema to reduce query times on large datasets. Includes changes to indexing strategies and field types.

  6. Reference Issues or Tickets
    If the commit is linked to a bug report or feature request, reference the issue number for clarity.
    Example: Fix login error (#123)

  7. Focus Each Commit on One Task
    Make sure each commit only addresses a single issue or task. This makes your version history easier to follow and understand.

  8. Use GitHub Desktop’s Message Fields
    When using GitHub Desktop, enter the commit subject in the 'Summary' box. If needed, provide additional details in the 'Description' field.


Examples of Good Commit Messages:

  • Add unit tests for payment processing module
  • Remove deprecated methods from API
  • Fix null pointer exception in user registration form

By following these guidelines, your commit messages will be more meaningful, making it easier for collaborators to understand and track changes in your project.