<commit_before>[![Financial Contributors on Open Collective](https://opencollective.com/husky/all/badge.svg?label=financial+contributors)](https://opencollective.com/husky) [![](https://img.shields.io/npm/dm/husky.svg?style=flat)](https://www.npmjs.org/package/husky) ![Node.js CI](https://github.com/typicode/husky/workflows/Node.js%20CI/badge.svg)

> Git hooks made easy

Husky improves your commits and more 🐶*woof!*

You can use it to lint your commit messages, run tests, lint code, etc... when you commit or push. Husky supports [all](https://git-scm.com/docs/githooks) Git hooks.

?> You're viewing documentation for husky v5, which is free to use in Open Source projects ❤️ and in early access for Sponsors 🎁. To use this new version at work, you can become a sponsor on [GitHub Sponsors](https://github.com/sponsors/typicode) or [Open Collective](https://opencollective.com/husky).<br><br>If you can't sponsor Husky, that's okay, [husky v4](https://github.com/typicode/husky/tree/master) is free to use in any project.

# Features

- Zero dependencies
- Lightweight
- Fast
- Supports macOS, Linux and Windows

# Usage

## Install

1. Install `husky` and [pinst](https://github.com/typicode/pinst) (optional)

```shell
# npm
npm install husky@next --save-dev
npm install pinst --save-dev # if your package is not private

# yarn
yarn add husky@next --dev
yarn add pinst --dev # if your package is not private
```

2. Enable Git hooks

```shell
npx husky install
yarn husky install
```

3. To automatically have Git hooks enabled after install, edit `package.json`

```js
// package.json
{
  "private": true,
  "scripts": {
    "postinstall": "husky install"
  }
}
```

!> **if your package is not private and you're publishing it on a registry like [npmjs.com](https://npmjs.com), you need to disable `postinstall` script using [pinst](https://github.com/typicode/pinst)**. Otherwise, `postinstall` will run when someone installs your package and result in an error.

```js
// package.json
{
  "private": false,
  "scripts": {
    "postinstall": "husky install",
    "prepublish": "pinst --disable",
    "postpublish": "pinst --enable"
  }
}
```

## Add a hook

To add a hook, you can use `husky add <hookname> [cmd]` (don't forget to run `husky install` before).

```shell
npx husky add pre-commit "npm test" # will create .husky/pre-commit file
```

Try to make a commit

```shell
git commit -m "Keep calm and commit"
```

If `npm test` command fails, your commit will be automatically aborted.

# Recipes

## Monorepo

It's recommended to add husky in root `package.json`. You can use tools like [lerna](https://github.com/lerna/lerna) and filters to only run scripts in packages that have been changed.

## Custom directory

If you want to install husky in another directory, for example `.config`, you can pass it to `install` command. For example:<commit_msg>docs: rename "prepublish" to "prepublishOnly" (#826)<commit_after>[![Financial Contributors on Open Collective](https://opencollective.com/husky/all/badge.svg?label=financial+contributors)](https://opencollective.com/husky) [![](https://img.shields.io/npm/dm/husky.svg?style=flat)](https://www.npmjs.org/package/husky) ![Node.js CI](https://github.com/typicode/husky/workflows/Node.js%20CI/badge.svg)

> Git hooks made easy

Husky improves your commits and more 🐶*woof!*

You can use it to lint your commit messages, run tests, lint code, etc... when you commit or push. Husky supports [all](https://git-scm.com/docs/githooks) Git hooks.

?> You're viewing documentation for husky v5, which is free to use in Open Source projects ❤️ and in early access for Sponsors 🎁. To use this new version at work, you can become a sponsor on [GitHub Sponsors](https://github.com/sponsors/typicode) or [Open Collective](https://opencollective.com/husky).<br><br>If you can't sponsor Husky, that's okay, [husky v4](https://github.com/typicode/husky/tree/master) is free to use in any project.

# Features

- Zero dependencies
- Lightweight
- Fast
- Supports macOS, Linux and Windows

# Usage

## Install

1. Install `husky` and [pinst](https://github.com/typicode/pinst) (optional)

```shell
# npm
npm install husky@next --save-dev
npm install pinst --save-dev # if your package is not private

# yarn
yarn add husky@next --dev
yarn add pinst --dev # if your package is not private
```

2. Enable Git hooks

```shell
npx husky install
yarn husky install
```

3. To automatically have Git hooks enabled after install, edit `package.json`

```js
// package.json
{
  "private": true,
  "scripts": {
    "postinstall": "husky install"
  }
}
```

!> **if your package is not private and you're publishing it on a registry like [npmjs.com](https://npmjs.com), you need to disable `postinstall` script using [pinst](https://github.com/typicode/pinst)**. Otherwise, `postinstall` will run when someone installs your package and result in an error.

```js
// package.json
{
  "private": false,
  "scripts": {
    "postinstall": "husky install",
    "prepublishOnly": "pinst --disable",
    "postpublish": "pinst --enable"
  }
}
```

## Add a hook

To add a hook, you can use `husky add <hookname> [cmd]` (don't forget to run `husky install` before).

```shell
npx husky add pre-commit "npm test" # will create .husky/pre-commit file
```

Try to make a commit

```shell
git commit -m "Keep calm and commit"
```

If `npm test` command fails, your commit will be automatically aborted.

# Recipes

## Monorepo

It's recommended to add husky in root `package.json`. You can use tools like [lerna](https://github.com/lerna/lerna) and filters to only run scripts in packages that have been changed.

## Custom directory

If you want to install husky in another directory, for example `.config`, you can pass it to `install` command. For example:
{'fraction_non_alphanumeric': 0.1312834686474348, 'fraction_numerical': 0.002936603903955778, 'mean_word_length': 4.206834532374101, 'pattern_counts': {'":': 16, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 26, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2523392', 'n_tokens_mistral': 1959, 'n_tokens_neox': 1834, 'n_words': 676}