Husky improves your commits and more 🐶 woof!
Husky helps us do more things along with git commands. For example, we can run
npm test in
pre-commit phase and do something else in
There is a bit difference between npm version below and above 7, so please check it by
#For npm npx husky-init && npm install #For Yarn 1 npx husky-init && yarn #For Yarn 2 yarn dlx husky-init --yarn2 && yarn
npm install --save-dev husky
- Enable git hooks
npx husky install
package.json, this script will be trigger enable Git hooks after install. This step also depeneds on our npm version
- npm > 7:
npm set-script prepare "husky install"
- npm < 7: copy
"prepare": "husky install"to
- npm > 7:
- Now we need to create a hook by command
husky add. After executing the below command, a line
npm testis added to a new file
.husky, which means
npm testwill be run before we actually commit.
npx husky add .husky/pre-commit "npm test"
If you use yarn2, here is your reference.
Buy me a coffee ☕ buymeacoffee.
I hope you had fun with git hook. I am really happy to receive your feedback on this article. Thanks for your precious time reading this.