DEV Community

Cover image for How To Set Up Git Hooks In An Nx Repo
Christian Lüdemann
Christian Lüdemann

Posted on

How To Set Up Git Hooks In An Nx Repo

#nx

Git hooks can be used to automate tasks in your development workflow. The earlier a bug is discovered, the cheaper it is to fix (and the less impact it has). Therefore it can be helpful to run tasks such as linting, formatting, and tests when you are e.g. committing and pushing your code, so any problems can be caught as early as possible.

This post will cover how to get an efficient development workflow using Git hooks that runs the necessary tasks at the correct times in your development workflow, all automatically.

TLDR:
We will use Husky to execute tasks for these hooks:

commit-msg: Ensuring our commit messages are following conventional commits format.
pre-commit: Run linting and formatting on staged files using lint-staged with eslint, style-lint and nx format:write.
pre-push: Run unit and component tests on affected projects.

You can read the blog post here.

Top comments (0)