> For the complete documentation index, see [llms.txt](https://tutorial.specian.co.uk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tutorial.specian.co.uk/project-setup/githook.md).

# GitHook

We are going to use the git `pre-commit` [hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks) to make sure the code gets *prettified* before committing it.

### Install Husky

> [Husky](https://github.com/typicode/husky) can prevent bad `git commit`, `git push` and more 🐶 *woof!*

```
$ yarn add husky pretty-quick -D
```

Add the following to the root `package.json`

{% code title="package.json" %}

```typescript
"husky": {
  "hooks": {
    "pre-commit": "pretty-quick --staged"
  }
}
```

{% endcode %}

Make sure husky is install

```
$ node node_modules/husky/lib/installer/bin install
```

Add it to `postinstall` to automate the process:

{% code title="package.json" %}

```typescript
"scripts": {
    "postinstall": "lerna bootstrap && node node_modules/husky/lib/installer/bin install"
}
```

{% endcode %}

When we commit, we should now see a message similar to this one:

```
🔍  Finding changed files since git revision 5053732.
🎯  Found 2 changed files.
✍️  Fixing up packages/api/index.ts.
✅  Everything is awesome!
```

{% hint style="info" %}
[`prettier`](https://github.com/florianherrengt/book-code/tree/prettier)branch available on GitHub.
{% endhint %}
