W
Werliton Silva
Guest
Have you ever wondered why some development teams have super organized, easy-to-understand, and standardized commit messages? Thatβs thanks to semantic commits and tools like commitlint.
In this article, Iβll show you how to start using these practices in your project with simple language and practical examples you can apply today.

Semantic commits are commit messages that follow a standardized structure. This helps you quickly understand what was done, enables automation (like changelogs), and improves collaboration between developers.

Letβs set up commitlint in a Node.js project. If you donβt have a project yet, you can create one with:
Create a file named
To make sure all commits follow the standard, weβll use Husky to run commitlint automatically.
Add this to your
Run the command
Inside the
Open the
Done! Now, if someone tries to make a commit that doesnβt follow the pattern, itβll be blocked.
Try making a commit with the message below:
Now try:
This one will be accepted!
Using semantic commits with
If you want to go further, you can integrate it with tools like Conventional Changelog, semantic-release, and more.
Did you enjoy this content? Let me know how you organize your commits!
Continue reading...
In this article, Iβll show you how to start using these practices in your project with simple language and practical examples you can apply today.
What Are Semantic Commits?

Semantic commits are commit messages that follow a standardized structure. This helps you quickly understand what was done, enables automation (like changelogs), and improves collaboration between developers.
Basic Structure
Code:
<type>(<scope>): <description>
- type: the kind of change (e.g.,
feat
,fix
,docs
, etc.) - scope: optional, indicates the part of the project affected
- description: a brief summary of the change
Examples
Code:
feat(auth): add Google login
fix(MYPROJ-1234): fix layout bug
docs(readme): update installation instructions
refactor(api): improve search performance
Installing Commitlint

Letβs set up commitlint in a Node.js project. If you donβt have a project yet, you can create one with:
Code:
npm init -y
1. Install the dependencies
Code:
npm install --save-dev @commitlint/{config-conventional,cli}
2. Create the config file
Create a file named
commitlint.config.js
in the root of your project:
Code:
module.exports = {
extends: ['@commitlint/config-conventional'],
};
Validating Commits with Husky
To make sure all commits follow the standard, weβll use Husky to run commitlint automatically.
1. Install Husky
Code:
npm install --save-dev husky
2. Enable hooks
Code:
npx husky install
Add this to your
package.json
:
Code:
"scripts": {
"prepare": "husky install"
}
3. Create the commit hook
- Create the
.husky
folder (if it doesn't already exist*)*:
Run the command
npx husky init
. This will initialize Husky and create the .husky
folder in the root of your project.
Code:
npx husky init
- Create the hook file directly:
Inside the
.husky
folder, create a new file with the name of the hook you need. For Commitlint, the file should be named commit-msg
.
Code:
# Use the 'touch' command on Unix/Linux systems or 'New-Item' in PowerShell (Windows)
touch .husky/commit-msg
- Add the validation script to the file:
Open the
.husky/commit-msg
file with a text editor and add the command that will run Commitlint. The standard command is npx --no-install commitlint --edit ${1}
.
Code:
#!/usr/bin/env sh
npx --no-install commitlint --edit "$1"
Note: Thenpx --no-install
command is more efficient because it uses the version of Commitlint that's already installed in your project (viapackage.json
), rather than installing it again on every run.
Done! Now, if someone tries to make a commit that doesnβt follow the pattern, itβll be blocked.
Testing It Out
Try making a commit with the message below:
Code:
git commit -m "fix layout bug"
This commit will be rejected because it doesnβt follow the format.
Now try:
Code:
git commit -m "fix(MYPROJ-1234): fix layout bug"

Conclusion
Using semantic commits with
commitlint
is a simple and powerful way to keep your project organized and professional. Even if youβre just starting out, itβs worth adopting this practice right away.If you want to go further, you can integrate it with tools like Conventional Changelog, semantic-release, and more.
Did you enjoy this content? Let me know how you organize your commits!

Continue reading...