Sharing Git Hooks With Your Team Using Husky
Git hooks are scripts that run at stages of your workflow (pre-commit, pre-push, etc.), but they live in .git/hooks — which isn't tracked by git. That makes sharing them with your team painful.
Husky solves this by storing hooks in a .husky/ directory inside your repo and setting core.hooksPath automatically via a prepare script.
Setup:
npm install husky --save-dev
npx husky install
Then add a hook:
npx husky add .husky/pre-commit "npm test"
New team members just run npm install and the prepare lifecycle script configures everything. One useful hook pattern: a prepare-commit-msg script that extracts a Jira ID from the branch name and prepends it to the commit message automatically.
You can skip hooks when needed with git --no-verify.