Husky: Native Git Hooks for Node.js
repository·main·Indexed Apr 15, 2026
https://github.com/typicode/huskyHusky is a lightweight (2 kB gzipped) and fast (~1ms) tool for managing Git hooks in Node.js projects. It utilizes the native Git feature core.hooksPath to run scripts like tests, linters, and formatters automatically before or after Git events such as commits and pushes. Husky supports all 13 client-side Git hooks, works across macOS, Linux, and Windows, and integrates with Git GUIs, version managers, monorepos, and CI environments. It aligns with npm best practices using the prepare script and allows for branch-specific hooks, POSIX shell scripting, and global disabling via the HUSKY environment variable.
What's inside husky
Overview and Features
mainOverview and Features (Spanish)
mainOverview and Features
mainHusky is a tool for managing Git hooks in Node.js projects. It simplifies the installation and execution of Git hooks, allowing developers to run scripts (like tests, linters, or formatters) automatically before or after Git events like commits or pushes.Getting Started
mainStart by following the Get Started guide to install and configure Husky in your project.
Sources:
docs/ru/index.mdInstall Husky with your package manager
mainInstall Husky as a development dependency using your preferred package manager. This adds the necessary binaries and scripts to your project.
# npm npm install --save-dev husky # pnpm pnpm add --save-dev husky # yarn yarn add --dev husky # Add pinst ONLY if your package is not private yarn add --dev pinst # bun bun add --dev huskynpm install --save-dev huskySources:
docs/es/get-started.mdНастроить Husky для CI-серверов и Docker
mainЧтобы избежать установки хуков на CI-серверах или в Docker, используйте
HUSKY=0.Пример для GitHub Actions:
env: HUSKY: 0Если устанавливаются только
dependencies(неdevDependencies):Скрипт
prepareможет завершиться ошибкой, так как Husky не установлен. Используйте один из следующих подходов:1. Игнорировать ошибку в
prepare:{ "scripts": { "prepare": "husky || true" } }2. Создать тихий скрипт установки:
Создайте
.husky/install.mjs:// Пропустить установку Husky в production и CI if (process.env.NODE_ENV === 'production' || process.env.CI === 'true') { process.exit(0) } const husky = (await import('husky')).default console.log(husky())Используйте его в
prepare:{ "scripts": { "prepare": "node .husky/install.mjs" } }Это предотвратит ошибки при отсутствии
huskyв продакшене.if (process.env.NODE_ENV === 'production' || process.env.CI === 'true') { process.exit(0) }Sources:
docs/ru/how-to.mdnpm
mainnpm install --save-dev huskyNote: Yarn has specific requirements; see the 'How-to' guide for details.
mainSources:
docs/ru/get-started.mdGet Started
mainFor detailed setup instructions, refer to the Get Started guide.
Sources:
docs/index.mdnpm
mainnpm install --save-dev huskyInstall Husky with your package manager
mainInstall Husky as a development dependency using your preferred package manager. If you use Yarn and your package is not private, you must also install
pinstto ensure hooks are preserved when publishing.```shell