Follow below steps
- Follow below commands
$ cd project
$ yarn add commitizen @commitlint/cli @commitlint/config-conventional husky -D
$ git init
$ npx commitizen init cz-conventional-changelog --save-dev --save-exact
- Open package.json and add like below
{
"name": "git-conventionalcommits",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
},
"devDependencies": {
"@commitlint/cli": "^8.3.5",
"@commitlint/config-conventional": "^8.3.4",
"commitizen": "^4.0.4",
"cz-conventional-changelog": "^3.1.0",
"husky": "^4.2.3"
},
"config": {
"commitizen": {
"path": "cz-conventional-changelog"
}
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
}
}
- Create commitlint.config.js file and paste below code
module.exports = { extends: ['@commitlint/config-conventional'] };
- Now try with git-cz command to commit