Lesson 12 of 19Article12 min
Husky Setup (Git Hooks)
CI minutes cost money and slow feedback loops. Husky runs git hooks locally so broken lint and failing unit tests never get pushed. Pair with lint-staged to only scan staged files — typically completes in under 10 seconds.
01Catch issues before CI
CI minutes cost money and slow feedback loops. Husky runs git hooks locally so broken lint and failing unit tests never get pushed. Pair with lint-staged to only scan staged files — typically completes in under 10 seconds.
Husky pre-commit flow
02Installation and configuration
Install Husky + lint-staged
npm install --save-dev husky lint-staged
npx husky init
echo "npx lint-staged" > .husky/pre-commit
# optional: run tests on push
echo "npm test -- --passWithNoTests" > .husky/pre-pushpackage.json lint-staged
{
"lint-staged": {
"*.{ts,tsx,js,jsx}": ["eslint --fix", "prettier --write"],
"*.{json,md}": ["prettier --write"],
"android/**/*.gradle": ["echo 'Review native changes manually'"]
}
}03Best practices
- Keep pre-commit fast — lint and format only; run full test suite on pre-push or CI.
- Document how to skip hooks in emergencies: git commit --no-verify (use sparingly).
- Ensure CI runs the same checks as hooks — no drift between local and remote.
- Add commit-msg hook for conventional commit format if using automated versioning.