DEV Community

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

Posted on

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.

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