Improve your Git Commit workflow

Sandro Marques
Oct 19, 2019 · 2 min read
Image for post
Image for post

The following steps lead you to improve your git commit messages as well as automating changelog and versioning.

Goals

Installation

Step 1 — Install husky, commitlint, cz-conventional-changelog and standard-version locally

yarn add --dev husky @commitlint/cli @commitlint/config-conventional cz-conventional-changelog standard-version

Step 2 — Install commitizen globally

sudo yarn global add commitizen

Step 3 — Update package.json

{
...
"scripts": {
"release": "standard-version"
},
"husky": {
"hooks": {
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
}
}

Step 4 — Create a commitlint.config.js file in your project root directory

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

Step 5 — Configure commitizen

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

Usage

Basically, instead of typing git commit now you type git cz which will open a wizard and help you write a standardized message.

Commitizen template
Commitizen template
Commitizen template

Commit with commitizen

Using commitizen to prompts a wizard

git add .
git cz
yarn release
git push --follow-tags

Pro tip

Run this command in your first release to prevent bumping the version in package.json

yarn release --first-release

Normal commit command

You can still use git commit ... but the commit will fail if the commit message is not properly formatted.

git add .
git commit -m "feat(blog): add comment section"
yarn release
git push --follow-tags

Commit but skip changelog, bump version and tag

git add .
git cz
yarn release --skip.changelog --skip.bump --skip.tag
git push

Credits

Conclusion

With these four packages, you can easily write meaningful commit messages with Conventional Commits. In addition, you will get the changelog automatically generated and with the correct version numbers. All this without any effort. This is awesome.

This article helped you? Please consider giving a few claps 👏.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch

Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore

Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

We’ve made changes to our Terms of Service and Privacy Policy. They take effect on September 1, 2020, and we encourage you to review them. By continuing to use our services, you agree to the new Terms of Service and acknowledge the Privacy Policy applies to you.