Modern native Git hooks made easy
Husky improves your commits and more 🐶 woof!
husky-init
is a one-time command to configure a project with husky.
It installs husky into your project and auto-configures your package.json,
ensuring that every time you run yarn|npm install
git is then configured to
use your hooks (so you don't have to worry about it again).
npx husky-init && npm install # npm
npx husky-init && yarn # Yarn 1
yarn dlx husky-init --yarn2 && yarn # Yarn 2+
pnpm dlx husky-init && pnpm install # pnpm
It will:
- install husky
- modify
package.json
(adding aprepare
script) - create a sample
pre-commit
hook that you can edit. By default this runsnpm test
when you commit.
- Install
husky
npm install husky --save-dev
yarn add --dev husky
- Enable Git hooks
npx husky install # will configure git to use .husky/ by default
- To automatically have Git hooks enabled after every npm/yarn install, edit
package.json
to use one of the npm/yarm lifecyle hooks e.g.prepare
.
npm set-script prepare "husky install"
You should have:
// package.json
{
"scripts": {
"prepare": "husky install"
}
}
https://typicode.github.io/husky
Important Upgrading from v4 to v7 requires migrating previous config, please see the docs.
MIT
Does your company use husky? Ask your manager or marketing team if your company would be interested in supporting this project.
Find husky helpful? Become a backer and show your appreciation with a monthly donation on Open Collective. You can also tip with a one-time donation.
GitHub sponsors can be viewed on my profile. All past and current Open Collective sponsors can be viewed on here.