Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.



Get Started Now!

How to write Git Commit Messages

When developers first step into the world of Git, they often encounter a certain discomfort, especially when it comes to crafting meaningful commit messages. The Git commit message, which encapsulates the changes made and why they were made, is a crucial part of version control. Developing good committing habits early in your career is essential. In this guide, we’ll explore how to improve your Git commit messages and why it matters.

The Importance of Quality Commit Messages

Imagine this scenario: you open a repository, run git log, and find a list of cryptic commit messages like “Fix style” or “Update code.” Months later, you revisit the project and have no idea what these messages mean. Sound familiar? Well, this is a common issue with poorly written commit messages. Quality commit messages provide essential context and save you and your teammates time when troubleshooting or understanding past changes.

The Anatomy of a Commit Message

A Git commit message has two main parts: the subject line and the body.

  • Subject Line: This should be concise, not exceeding 50 characters. It should start with a capital letter and use the imperative mood (e.g., “Add,” “Fix,” “Update”). The subject line provides a high-level overview of the change.
  • Body: The body of the message is where you can explain in more detail. It should be wrapped at 72 characters and answer the questions of “why” and “what.”

Steps to Writing Better Commit Messages

Let’s dive into practical steps to improve your commit messages:

1. Capitalization and Punctuation

Always start the subject line with a capital letter and don’t end it with punctuation. Conventional Commits, a popular convention, encourages using all lowercase.

2. Mood Matters

Use the imperative mood in the subject line. This creates a tone of giving an order or request. For example, “Fix the dark mode toggle state” is more appropriate than “Fixed the dark mode toggle state.”

3. Specify the Type of Commit

It’s beneficial to categorize your commits. Use a consistent set of words to describe your changes. For example, “Bugfix,” “Update,” “Refactor,” or “Bump.” This helps in classifying and searching for specific types of changes.

4. Watch the Length

Keep the subject line short, ideally under 50 characters, and restrict the body to 72 characters per line. This ensures messages are concise and readable.

5. Content Clarity

Be direct and avoid filler words and phrases. Think like a journalist, aiming to answer the “what” and “why” questions. Pretend that the reader has no prior knowledge of the change and needs a clear explanation.

Conventional Commits

Conventional Commits is a widely adopted format that provides structured commit messages. It uses the format: <type>[optional scope]: <description>. The type can include values like “feat” (new feature), “fix” (bug fix), “chore” (maintenance), and more. The optional scope specifies the part of the codebase affected, and the description provides a concise summary.

This convention enhances consistency in commit messages and can be paired with tools like Commitizen to enforce standards.

Commit Message Comparisons

Let’s compare some examples to see the difference quality commit messages make:

Good:

  • feat: Improve performance with lazy load implementation for images
  • chore: Update npm dependency to the latest version
  • Fix bug preventing users from submitting the subscribe form
  • Update incorrect client phone number within the footer body per client request

Bad:

  • Fixed bug on the landing page
  • Changed style
  • Oops
  • I think I fixed it this time?
  • Empty commit messages

By following these guidelines, your commit messages can become valuable documentation, saving you and your team time and frustration. Whether you’re working solo or in a collaborative development environment, investing a little extra effort in crafting clear and meaningful commit messages pays off in the long run.

Related Posts

Master DevOps with the Best Free Tutorials Online

The demand for DevOps professionals is skyrocketing as organizations rapidly adopt modern development and deployment methodologies. Whether you are a beginner looking to enter the DevOps space…

Error in Laravel:”Invalid Key Supplied”

while trying to log in to your Laravel application, don’t worry. This issue is commonly related to misconfigured or missing keys for Laravel Passport’s OAuth2 authentication system….

Error in Laravel “Davmixcool\MetaManager\MetaServiceProvider Not Found”

When working on Laravel projects, developers often encounter errors during the setup or runtime process. One such error is the “Class ‘Davmixcool\MetaManager\MetaServiceProvider’ not found”, which can occur…

Discover Rewa Effortlessly with Motoshare’s Convenient Bike and Car Rentals

Rewa, the “Land of White Tigers,” offers a unique blend of historical, cultural, and natural attractions that captivate every traveler. To make exploring this charming city more…

Discover Shimoga (Shivamogga) Effortlessly with Motoshare’s Bike and Car Rentals

Nestled in the lush greenery of Karnataka, Shimoga (Shivamogga) is a haven for nature lovers and history enthusiasts. From the roaring Jog Falls to the tranquil forests…

Explore the Spiritual Charm of Mathura with Motoshare’s New Bike and Car Rental Services

Mathura, the birthplace of Lord Krishna, is a city brimming with spirituality, vibrant culture, and historical significance. To make your journey through this sacred city seamless, Motoshare…

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x