R
Rishtaara
React Native Advanced: CI/CD Pipeline Mastery
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.

Catch 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

Installation 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-push
package.json lint-staged
{
  "lint-staged": {
    "*.{ts,tsx,js,jsx}": ["eslint --fix", "prettier --write"],
    "*.{json,md}": ["prettier --write"],
    "android/**/*.gradle": ["echo 'Review native changes manually'"]
  }
}

Best 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.