← Back to list

How to Set Up Commitlint to Enforce Clean Git Commit Messages

Ensure consistent commit messages with Commitlint for better collaboration and changelogs.

Sikandar Dev · 2025-10-11 03:35 · 1 claps · 1.1 min read
#git #commit-lint #conventional-commits #husky #commitizen
Open on Medium ↗
Wiki topics: 🔓 · Open Source 📊 · Economic Policy 🧘 · Spirituality

How to Set Up Commitlint to Enforce Clean Git Commit Messages

[embed]YouTube Video Url

Introduction

Writing consistent and meaningful Git commit messages improves collaboration, code readability, and changelog generation.

[Commitlint](https://commitlint.js.org/?utm_source=chatgpt.com) enforces rules on your commit messages, ensuring your team follows a standardized format such as **Conventional Commits**.

In this post, you’ll learn how to install and configure Commitlint in just a few steps.

Installation

Using pnpm:

pnpm add -D @commitlint/{cli,config-conventional}

Or with npm:

npm install --save-dev @commitlint/cli @commitlint/config-conventional

Create Commitlint Config

Add a commitlint.config.js file at the root of your project:

// commitlint.config.js
module.exports = {
  extends: ['@commitlint/config-conventional'],
};

This enforces the Conventional Commits style (feat:, fix:, docs:, etc.).

Add Git Hook with Husky (Recommended)

To enforce commit message rules automatically:

Install Husky

pnpm add -D husky
npx husky install

Enable Git Hooks

In package.json:

"scripts": {
  "prepare": "husky install"
}

Then run:

pnpm run prepare

3. Add Commit-msg Hook

npx husky add .husky/commit-msg 'npx --no -- commitlint --edit $1'

Now every commit message will be validated automatically.

Note: If your project isn’t a Git repo, run git init first. Husky will then enforce Commitlint on every commit.

Optional: Customize Rules

Edit commitlint.config.js to define your own rules:

module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [
      2, 'always',
      ['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore']
    ],
  },
};

Pro Tip: Use Commitizen

For guided commit prompts:

pnpm add -D commitizen

In package.json:

"scripts": {
  "commit": "cz"
}

Run:

pnpm commit

You’ll be prompted step-by-step to create a valid commit message.

Conclusion

With Commitlint and Husky:

  • Every commit follows a consistent format.
  • Teams get cleaner collaboration & better automation.
  • Changelogs become easier to generate.

Start using it today and level up your workflow!


메타데이터
post_id
9082cce5ca03
slug
how-to-set-up-commitlint-to-enforce-clean-git-commit-messages-9082cce5ca03
url
https://medium.com/@the.sikandar.dev/how-to-set-up-commitlint-to-enforce-clean-git-commit-messages-9082cce5ca03
canonical_url
https://medium.com/@the.sikandar.dev/how-to-set-up-commitlint-to-enforce-clean-git-commit-messages-9082cce5ca03
author_url
https://medium.com/@the.sikandar.dev
status
ok
fetched_at
2026-07-17 02:32:58