How to Write Better Git Commit Messages — A Step-By-Step Guide

Sanjana Human In Tech
3 min readDec 27, 2023

--

Git commit message

Writing clear and meaningful Git commit messages is an essential aspect of maintaining a healthy and understandable version history for your React Native project.

Here’s a step-by-step guide to help you write better Git commit messages:

1. Use the Imperative Mood:

Start your commit message with an imperative verb. This makes your commit messages sound like a command. For example:

  • “Add feature”
  • “Fix bug”
  • “Update documentation”

2. Keep it Short and Concise:

Try to keep your commit messages short and to the point. Ideally, they should be around 50 characters or less. If more details are needed, use the body of the commit message.

3. Summarize in the First Line:

The first line of your commit message should be a concise summary of the change. It should be able to stand alone and provide a clear idea of what the commit is about.

4. Separate Subject and Body:

If your commit message needs more explanation, separate the subject from the body with a blank line. Use the body to provide additional context and details.

Add feature

- Implemented a new component for better user interaction
- Updated dependencies to the latest versions

5. Use the 50/72 Rule:

The first line (subject) should be limited to 50 characters, and the following lines (body) should be wrapped at 72 characters. This makes it easier to read in various Git tools.

6. Provide Context:

Explain why you’re making the change. Describe the problem or the motivation behind the commit. This helps anyone reading the commit history to understand the reasoning behind the change.

7. Reference Issues:

If your commit relates to a specific issue or task, reference it in your commit message. Most issue tracking systems allow you to link commits to issues, making it easier to trace changes.

Fix issue #123: Unable to login with invalid credentials

8. Use Keywords:

Consider using specific keywords in your commit messages to convey the nature of the change. Some common keywords include “Fix,” “Add,” “Update,” “Remove,” etc.

9. Be Consistent:

Establish a consistent style for your commit messages across the entire project. Consistency makes it easier for contributors to understand the commit history.

10. Proofread:

Before committing, take a moment to review your commit message. Make sure it accurately reflects the changes and follows the guidelines outlined above.

Example Commit Messages:

Add feature: Integrate push notifications

- Implemented Firebase Cloud Messaging for real-time updates
- Updated README with setup instructions

Fix bug: Resolves issue #456

- Fixed a memory leak in the image caching module
- Added unit tests for the affected components

By following these steps, you’ll contribute to a clear, informative, and well-documented version history for your React Native project. This, in turn, makes it easier for your team and future contributors to understand the changes made over time.

Thank you for reading this article! Don’t forget to clap.

If you have any queries related to ReactNative, I’m always happy to help you. You can reach me on LinkedIn and Gmail.

--

--

Sanjana Human In Tech
Sanjana Human In Tech

Written by Sanjana Human In Tech

A React Native front-end enthusiast and dedicated development engineer, eager to expand knowledge on development techniques and collaborate with others.

Responses (1)