DEV Community

Cover image for Mastering Git Commit Messages with Conventional Commits
Naser Rasouli
Naser Rasouli

Posted on

4

Mastering Git Commit Messages with Conventional Commits

✳️ Why Should We Care About Commit Message Structure?

In any software project, every small change made to the codebase is recorded in Git history. This history is not just a log of what happened — it's a crucial tool for tracking changes, collaborating with others, managing releases, and automating development workflows.
But when commit messages are written inconsistently or without structure:

  • It becomes hard to understand why a change was made
  • Generating changelogs becomes manual and time-consuming
  • CI/CD tools can’t effectively leverage the commit history
  • And in team environments, others struggle to follow your changes

This is where Conventional Commits come into play. It’s a simple but powerful convention that allows us to write commit messages in a structured, readable, and machine-parsable way — making life easier for both developers and tools.

🧠 What is Conventional Commits?

Conventional Commits is a standardized convention for writing commit messages in Git. It helps developers write structured, meaningful, and automatable messages to track changes more effectively.

🏗 Commit Message Structure

<type>(optional scope): <short description>
[optional body]
[optional footer(s)]
Enter fullscreen mode Exit fullscreen mode

Main Components:
type: The type of change (required)
scope: The section of the codebase affected (optional)
description: A concise summary of the change (required)
body: A more detailed explanation (optional)
footer: Used for issue references or breaking changes (optional)

🧩 Common Commit Types

| Type     | Purpose                                          |
| -------- | ------------------------------------------------ |
| feat     | A new feature                                    |
| fix      | A bug fix                                        |
| docs     | Documentation-only changes                       |
| style    | Code formatting (whitespace, etc.)               |
| refactor | Code changes that don’t fix bugs or add features |
| test     | Adding or updating tests                         |
| chore    | Miscellaneous tasks (build tools, etc.)          |
Enter fullscreen mode Exit fullscreen mode

🧪 Real-World Examples
Now that you understand the structure and purpose of Conventional Commits, let’s see how they’re actually used in real development workflows.
In this section, we’ll walk through practical examples of commit messages for common scenarios — from adding features and fixing bugs to making documentation updates and handling breaking changes.
These examples will help you apply the convention correctly and consistently in your own projects.

1. Adding a New Feature

feat(cart): add quantity selector to cart items
Enter fullscreen mode Exit fullscreen mode

2. Fixing a Bug

fix(auth): resolve issue with token refresh on expiration
Enter fullscreen mode Exit fullscreen mode

3. Documentation Update

docs(readme): update usage example for CLI
Enter fullscreen mode Exit fullscreen mode

4. Styling Change

style(ui): reformat buttons and inputs using Tailwind
Enter fullscreen mode Exit fullscreen mode

5. Code Refactoring

refactor(api): simplify data fetch logic in product service
Enter fullscreen mode Exit fullscreen mode

6. Breaking Change (Incompatible)

feat!: drop support for Node.js v12
Enter fullscreen mode Exit fullscreen mode

✅ Final Thoughts
Conventional Commits help create a clean, consistent, and automatable Git history. This is especially beneficial in team-based, open-source, or large-scale projects that rely on version control and automation.

ACI image

ACI.dev: Best Open-Source Composio Alternative (AI Agent Tooling)

100% open-source tool-use platform (backend, dev portal, integration library, SDK/MCP) that connects your AI agents to 600+ tools with multi-tenant auth, granular permissions, and access through direct function calling or a unified MCP server.

Star our GitHub!

Top comments (4)

Collapse
 
nevodavid profile image
Nevo David

pretty cool how much structure can help, tbh i still forget the right type sometimes lol

Collapse
 
naserrasouli profile image
Naser Rasouli

Totally feel you! 😅 It takes a bit of getting used to, but once it clicks, it really pays off. I still keep a cheat sheet nearby — or use tools like Commitizen so I don’t have to memorize every type. Super helpful!

Collapse
 
saman_z4_244ca2c62a4f6f88 profile image
Saman Z4

Greatest 🤴

Collapse
 
naserrasouli profile image
Naser Rasouli

Tnx saman

AWS Q Developer image

Build your favorite retro game with Amazon Q Developer CLI in the Challenge & win a T-shirt!

Feeling nostalgic? Build Games Challenge is your chance to recreate your favorite retro arcade style game using Amazon Q Developer’s agentic coding experience in the command line interface, Q Developer CLI.

Participate Now

👋 Kindness is contagious

Explore this insightful write-up, celebrated by our thriving DEV Community. Developers everywhere are invited to contribute and elevate our shared expertise.

A simple "thank you" can brighten someone’s day—leave your appreciation in the comments!

On DEV, knowledge-sharing fuels our progress and strengthens our community ties. Found this useful? A quick thank you to the author makes all the difference.

Okay