How to set up Commitzen with Husky

how-to-set-up-commitzen-with-husky

Conventional commits specification contains a set of rules for creating an explicit commit history, which makes it easier to write automated tools on top of, for example, semantic release. You can manually follow this convention in your project or use a tool to assist you, such as Commitizen.

There are some ways to use Commitizen in your project, in this post, I will show you how to set it up with Husky, so whenever you run git commit, you’ll be prompted to fill out any required commit fields at commit time.

To start, install Commitzen and Husky packages:

npm i commitizen husky --save-dev

Next, initialize your project to use the cz-conventional-changelog adapter

commitizen init cz-conventional-changelog --save-dev --save-exact

That command will do the following:

  1. Install the cz-conventional-changelog adapter npm module;

  2. Save it to package.json‘s dependencies or devDependencies;

  3. Add the config.commitizen key to the root of your package.json.

Finally, in the package.json file, set a Husky´s hook to trigger Commitzen on commit command

"husky": {
  "hooks": {
    "prepare-commit-msg": "exec < /dev/tty && npx cz --hook || true"
  }
}

And that´s it, you are all set. Make some changes to your code, run git commit, and follow the Commitzen instructions.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
-level-up-your-hacktoberfest-game-with-these-new-treats-

🚀 Level up your Hacktoberfest game with these new treats 🍫

Next Post
which-is-better:-in-person-or-remote-coding-interviews?

Which is Better: In-Person or Remote Coding Interviews?

Related Posts