Improve Your Git Commits by Using Conventional Commits
Git commits are the foundation of collaboration in software development. Writing clear and structured commit messages significantly improves readability, makes the project's history easier to understand, and simplifies future maintenance. One popular approach to ensuring commit clarity is the use of Conventional Commits.
What Are Conventional Commits?
Conventional Commits is a simple, standardized way of writing Git commit messages. It creates a clear format that makes it easy to understand the type and scope of changes at a glance.
Structure of a Conventional Commit
A Conventional Commit typically follows this simple structure:
<type>([optional scope]): <short description>
[optional body]
[optional footer]
Let’s break down each part:
- Type (mandatory): Indicates the kind of change you made.
- Optional Scope: Specifies the context or specific component affected by the change, e.g., database, UI, API, etc.
- Short Description: Brief and concise summary of the commit.
- Optional Body: Detailed description, explaining more thoroughly what the change accomplishes.
- Optional Footer: Used to highlight breaking changes or to reference issues or tickets.
Common Commit Types
Here are some of the most commonly used commit types in Conventional Commits:
feat
: A new feature.fix
: Bug fixes.docs
: Documentation updates.style
: Changes that don't affect code behavior, like formatting.refactor
: Code changes that neither fix bugs nor add features.test
: Adding or updating tests.perf
: Performance improvements.chore
: Routine tasks that don’t affect the main codebase (e.g., updating build scripts).build
: Changes affecting build systems or external dependencies.ci
: Adjustments related to continuous integration.
Examples of Conventional Commits
Here are some practical examples:
Adding a New Feature
feat: add user authentication functionality
Implemented user login and registration with JWT tokens.
Bug Fixes with Issue Reference
fix(payment): resolve incorrect total calculation
Fixed an issue causing total amounts to be miscalculated during checkout.
Fixes: #101
Formatting or Styling Changes
style: apply code formatting standards
Applied consistent indentation and spacing according to guidelines.
Build System Updates
build(deps): update React version to "18.2.0"
Tools to Automate Conventional Commits
Adopting Conventional Commits manually can be tedious, especially at first. But it is an important process needed for readable commits and when working with teams. I felt the need to automate this process of getting the message written properly so I built CommitCraft
CommitCraft is a command-line tool designed to streamline the process of creating structured commit messages according to the Conventional Commits specification. With CommitCraft, you no longer need to remember the commit types or worry about formatting—> it generates clear and compliant commit messages effortlessly.
Check out CommitCraft:
Start using Conventional Commits today and bring clarity, structure, and consistency to your project’s commit history!