Imagine: you push code, and CI fails due to an unformatted file that was forgotten to be run through a linter. Or a commit message like 'fix' — a month later no one remembers what changed. We've encountered this on every second project over more than 5 years in web development. After implementing Husky in 50 projects, we cut code-review time by 30% and halved merge conflicts. Average team time savings: tens of hours per month. A missed error in production can be costly, so automating Git hooks is not a luxury but a necessity. Order a turnkey Husky setup — we guarantee results.
What Does Husky Setup for Git Hooks Provide?
Husky is a Git hooks manager that runs arbitrary scripts on events: pre-commit, commit-msg, pre-push, prepare-commit-msg. Typical scenarios — automatic linting, type checking, tests, commit message validation. Unlike CI, Husky catches errors locally before pushing to the repository — faster and cheaper: one setup saves 10+ hours per month for a team of 5 developers.
| Hook | Event | Typical Action | Execution Time |
|---|---|---|---|
| pre-commit | Before creating a commit | Lint and format staged files | <1 second |
| commit-msg | After entering the commit message | Validate format (Conventional Commits) | <0.5 seconds |
| pre-push | Before pushing to remote repository | Run tests, typecheck | 1–5 minutes |
| prepare-commit-msg | When creating a commit (before editor) | Auto-add task number | <0.5 seconds |
How Husky Prevents Errors on Commit?
Husky works at the Git event level before changes enter history. For pre-commit we use lint-staged — it's 5 times faster than running a linter on the whole project. And the commit-msg hook with commitlint blocks commits with invalid messages before saving. 90% of linting errors are caught before commit.
How We Configure Husky?
Setting up Husky includes several steps. Here is a step-by-step guide we use on every project:
- Install Husky, lint-staged, and commitlint — one command.
- Initialize Husky — creates the .husky directory.
- Configure pre-commit hook — lint staged files.
- Configure commit-msg hook — validate messages per Conventional Commits.
- Configure pre-push hook — run tests and typecheck.
- Verify functionality — test each hook.
The process takes from 20–30 minutes for a basic configuration to an hour for a full set.
Installation and Basic Configuration — Full Husky Setup
npm install --save-dev husky lint-staged @commitlint/cli @commitlint/config-conventional npx husky init After init, a .husky/ directory is created with a basic pre-commit hook and a "prepare": "husky" script is added to package.json. The prepare script runs automatically on npm install — new team members get hooks without extra steps.
Pre-commit Hook
.husky/pre-commit:
npx lint-staged Runs lint-staged — applies commands (eslint, prettier) only to staged files. Configuration in package.json or a separate lint-staged.config.js.
Commit-msg Hook with commitlint
Create .husky/commit-msg:
npx --no -- commitlint --edit $1 And commitlint.config.mjs:
export default { extends: ['@commitlint/config-conventional'], rules: { 'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore', 'revert', 'perf', 'ci']], 'subject-max-length': [2, 'always', 72], 'body-max-line-length': [2, 'always', 100], }, }; Valid commit: feat: add user authentication. Invalid: added stuff — the hook will block.
Pre-push Hook
To run tests and typecheck before push: .husky/pre-push:
npm run test:ci npm run typecheck Tests before push, not before every commit — a compromise between speed and reliability. Pre-push is 3 times faster than a full CI run because it excludes build and deploy.
What's Included in Husky Setup?
- Installation and configuration of Husky — set up required hooks.
- Configuration of lint-staged — rules for eslint/prettier on staged files.
- Configuration of commitlint — Conventional Commits rules.
- Documentation — short instruction for the team.
- Testing — verify hooks work correctly.
- Support — answer questions within a week after setup.
| Approach | Initial Setup | Speed on Commit | Error Protection |
|---|---|---|---|
| Manual (linter only) | 0 minutes | Fast (no checks) | Low |
| CI after push | 10–30 minutes | Fast | Medium (errors visible only in CI) |
| Husky + CI | 60 minutes | Fast (staged files only) | High (errors caught locally and in CI) |
Contact us to discuss details and get a custom proposal. Order a turnkey setup — we guarantee results. Get a free consultation on integrating Husky into your project.







