Husky
Installation
Section titled “Installation”See the official documentation.
npm i -D huskyyarn add -D huskypnpm add -D huskybun add -d huskyInitialize husky:
npx husky inityarn dlx husky initpnpx husky initbunx husky initSettings
Section titled “Settings”Pre-commit Hook
Section titled “Pre-commit Hook”This hook runs before each commit to lint and format your staged files.
#!/usr/bin/env sh. "$(dirname -- "$0")/_/husky.sh"
pnpm run lint-stagedCommit-msg Hook
Section titled “Commit-msg Hook”This hook runs after you enter a commit message to validate its format.
#!/usr/bin/env sh. "$(dirname -- "$0")/_/husky.sh"
npx --no -- commitlint --edit $1Once configured, husky will automatically run the hooks at the appropriate times during your git workflow:
pre-commit: Runs beforegit commitcompletescommit-msg: Validates the commit message format
Add this script to your package.json to ensure husky is set up when installing dependencies:
"prepare": "husky"To skip hooks temporarily (use sparingly):
git commit --no-verify -m "message"