Skip to content

Husky

See the official documentation.

Terminal window
npm i -D husky

Initialize husky:

Terminal window
npx husky init

This hook runs before each commit to lint and format your staged files.

.husky/pre-commit
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
pnpm run lint-staged

This hook runs after you enter a commit message to validate its format.

.husky/commit-msg
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"
npx --no -- commitlint --edit $1

Once configured, husky will automatically run the hooks at the appropriate times during your git workflow:

  • pre-commit: Runs before git commit completes
  • commit-msg: Validates the commit message format

Add this script to your package.json to ensure husky is set up when installing dependencies:

package.json
"prepare": "husky"

To skip hooks temporarily (use sparingly):

Terminal window
git commit --no-verify -m "message"