About Me / Projects / CustomGPTs / Blog / Apps / Games

The Art of Conventional Commits 🖋️

Author's Profile Picture

Bilal A.

Picture this: It's deployment day, and the production server is on fire. Your team is scrambling to identify the cause, but the commit history looks like a cryptic diary: "fixed stuff," "updates," "another fix." Frustration mounts as no one can trace the issue quickly, and the team burns hours trying to untangle the mess.

a developer having a bad time because git history is ambiguous.

Another evening lost because of a cryptic git history!

This nightmare scenario is all too familiar for many development teams.

But it doesn’t have to be this way.

Enter Conventional Commits: a standardized format for writing commit messages that brings order to the chaos and sets your team up for success.

By the end of this post, you’ll understand how Conventional Commits work and why they’re important. You’ll learn how to structure clear and consistent commit messages, improve teamwork, and simplify your development process. Plus, you’ll pick up practical tips to help your team adopt this system and make your workflow more efficient.

What Are Conventional Commits?

Conventional Commits is a lightweight convention for writing commit messages. It specifies a structure that not only makes messages more readable but also empowers teams to automate workflows like versioning, changelog generation, and CI/CD pipelines.

A Conventional Commit message typically includes a type, an optional scope, and a description, making it immediately clear what the commit does.

What Does A Conventional Commit Look Like?

feat: add navigation bar to dashboard
        
Added a fully responsive navigation bar to the dashboard.
        

This format allows other developers to instantly understand that a new feature ("feat") was added and what it does.

What Does An Ambiguous Commit Look Like?

updated stuff
        

This commit message is vague and provides no context about what was updated. Without clear information, team members can’t quickly identify what changes were made or why. For example, it’s unclear whether this was a bug fix, a new feature, or a minor style adjustment. Poor commit messages like this slow down debugging, hinder collaboration, and reduce the overall quality of the project’s history.

Conventional Commit Matrix

Type Purpose Semantic Version Increment
feat Indicates a new feature. Minor (e.g., 1.0.0 to 1.1.0)
fix Represents a bug fix. Patch (e.g., 1.0.0 to 1.0.1)
docs Documentation changes (e.g., README updates). None
style Code style changes (e.g., formatting, white-space) that do not affect functionality. None
refactor Code changes that neither fix a bug nor add a feature. None
test Adding or modifying tests. None
BREAKING CHANGE Highlights a major change that requires user action (e.g., API redesign). Major (e.g., 1.0.0 to 2.0.0)

Each commit message is a self-contained unit of information, with types like feat, which signifies a new feature, or fix, which denotes a bug fix. docs is used for documentation updates, while style covers non-functional formatting changes like whitespace adjustments. The refactor type applies to restructuring code without altering behavior, and test focuses on additions or modifications to tests. The BREAKING CHANGE tag signals major updates requiring user action, often tied to significant system or API overhauls. This structured approach ensures that your commit history is not just meaningful but actionable, offering clear insights for debugging and project tracking.

Conventional Commit Benefits

1. Consistency Across Commit Messages

A uniform structure ensures that all commit messages are clear, easy to read, and meaningful, fostering better collaboration across teams. For example, instead of vague messages like "changes", developers can use messages like fix(auth): resolve login issue. This clarity ensures everyone understands the context of a change immediately.

2. Automated Release Management

Tools like semantic-release can parse commit messages to automatically determine the next version number and publish releases. For instance, a feat: add dark mode commit can trigger a minor version bump, while a fix: correct typo in navbar commit might result in a patch release. This automation saves time and reduces manual errors during versioning.

3. Easier Changelog Generation

Adhering to this convention allows tools to automatically generate changelogs that accurately reflect changes in the codebase. For example, commits labeled feat and fix can be listed under "Features" and "Bug Fixes" sections, respectively, providing a clear overview of updates in each release.

4. Improved Traceability

Commit types and scopes provide clear context, making it easier to trace changes and debug issues. For example, if a bug reappears in a deployment, the commit message fix(payment): handle null pointer exception immediately directs the team to the relevant code and context for debugging.

5. Enhanced CI/CD Integration

Conventional Commits can trigger specific CI/CD workflows. For instance, a feat: implement search functionality commit might deploy a feature branch to staging, while a fix: resolve API timeout issue commit could automatically run regression tests to verify stability. This integration ensures smoother and faster development cycles.

For larger teams, enforcing commit standards can be automated using prehook scripts. Prehook scripts are scripts that run before a commit is finalized in Git. They validate the commit message format to ensure it aligns with standards like Conventional Commits, and they can also perform additional checks such as running linters or unit tests to maintain code quality. For example, you can use a tool like Husky to implement a prehook that checks if the commit message starts with a valid type, such as feat, fix, or docs. Additionally, a prehook can block commits if tests fail, preventing broken code from entering the repository. This automation ensures that only properly formatted and tested commits are pushed, saving time during reviews and reducing errors in production.

While tools and scripts help enforce the standard, the real success lies in making this approach a team habit. Regularly discuss the importance of meaningful commit messages, and review them during code reviews to reinforce the practice.

Conventional Commits are a simple yet powerful way to bring structure, clarity, and efficiency to your development workflow. From enabling automated releases to improving collaboration, this methodology positions your team for long-term success.

What do you think about Conventional Commits? Are there other strategies you’ve found helpful for maintaining clean commit histories? Share your thoughts in the comments below!