Skip to content

Conventional Commits: A Journey to Better Team Collaboration

Estimated time to read: 6 minutes

In the world of software development, collaboration is the key to success. But have you ever felt lost in a sea of cryptic commit messages or struggled to understand why certain changes were made? If so, you're not alone. Imagine reading through your project's commit history and instantly understanding what each change does without diving into the code. Sounds refreshing, right? That's the beauty of Conventional Commits.

By adopting a standard way of writing commit messages, we can enhance clarity, improve collaboration, and even automate parts of our workflow. Many of us have been there, and that's where Conventional Commits come into play. Let's take a walk together through the concept of Conventional Commits and see how they can transform your team's workflow.

The Problem with Unconventional Commits

We've all seen commit messages like "Update," "Fix bug," or worse, "Stuff." These vague messages leave us scratching our heads, trying to decipher what changed and why. This lack of clarity can lead to:

  • Miscommunication: Team members may not understand the purpose of changes.
  • Wasted Time: Developers spend extra time digging into code to find details.
  • Errors: Without clear context, it's easier to overlook important information.

But don't worry; there's a solution!


What Are Conventional Commits?

Conventional Commits provide a simple and consistent structure for commit messages. They help us communicate changes clearly, making our project's history more readable and maintainable.

Here's the basic format:

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Types include things like feat for new features or fix for bug fixes. By following this format, we make it easier for everyone on the team to understand what's happening.


Breaking Down a Conventional Commit

Let's look at an example together:

feat(auth): add OAuth2 login support

Implemented OAuth2 login using Google's API. Users can now log in with their Google accounts.

Closes #45
  • Type: feat indicates a new feature.
  • Scope: (auth) specifies the area affected.
  • Description: Brief summary of the change.
  • Body: Provides more details.
  • Footer: References issue number #45.

Isn't that much clearer than just "Add login"?

Types of Commit Messages

Most commonly used types in Conventional Commits are:

  • feat: A new feature
  • fix: A bug fix
  • docs: Documentation changes
  • style: Code style changes (formatting, missing semi-colons, etc.)
  • refactor: Code changes that neither fix a bug nor add a feature
  • perf: Performance improvements
  • test: Adding or correcting tests
  • chore: Changes to the build process or auxiliary tools

Why Should We Use Them?

Adopting Conventional Commits brings several benefits:

  1. Clear Communication: Everyone understands what each commit does.
  2. Automated Changelogs: Tools can generate release notes automatically.
  3. Simplified Code Reviews: Reviewers can focus on the code, not guessing intentions.
  4. Consistent History: A clean and organized commit history helps future team members.

Think of it as speaking a common language within your team.


Getting Started with Conventional Commits

So, how do we begin?

Step 1: Discuss with Your Team

  • Share the Idea: Bring up Conventional Commits in your next team meeting.
  • Highlight the Benefits: Explain how it will make everyone's life easier.

Step 2: Agree on the Types and Scopes

  • Customize as Needed: Decide which types (feat, fix, docs, etc.) make sense for your project.
  • Define Scopes: Identify the main areas of your codebase.

Step 3: Start Writing Conventional Commits

  • Lead by Example: Begin using the format in your commits.
  • Encourage Others: Gently remind team members to adopt the practice.

Tips for Success

Here are some friendly tips to help you and your team embrace Conventional Commits:

  • Keep Messages Short and Sweet: Aim for a concise subject line.
  • Use Active Voice: Write as if you're giving a command (e.g., "Add feature" instead of "Added feature").
  • Be Consistent: Stick to the agreed-upon types and format.
  • Don't Stress Over Perfection: It's okay to make mistakes as you learn.

Remember, the goal is to improve communication, not to add extra stress.


Tools to Help You Along the Way

There are some great tools out there to assist us:

Commitlint

  • What It Does: Checks your commit messages against the Conventional Commits format.
  • How It Helps: Provides immediate feedback, so you know if your commit message needs tweaking.

Husky

  • What It Does: Allows you to run scripts before commits.
  • How It Helps: You can set up Husky to run Commitlint automatically.

Semantic Release

  • What It Does: Automates the release process based on commit messages.
  • How It Helps: Generates changelogs, bumps version numbers, and publishes packages.

These tools take some of the heavy lifting off our shoulders.

Success

We've walked through the concept of Conventional Commits together, exploring how they can make our team's collaboration smoother and more efficient. By adopting this simple practice, we can save time, reduce confusion, and focus more on what we love—coding!

References

If you're interested in learning more, here are some resources to check out: