#
husky
#
Introduction
Husky is a tool that allows you to add Git hooks to your project. This allows you to run scripts before committing, pushing, etc. For example, you can use it to check if your code is formatted correctly before committing it. We use it to check if the commit message is formatted correctly based on the code consistency rules.
Commitlint is also installed with husky.
#
Step 1: Initialize Git
To use husky you need to have a git repository initialized.
If you have already initiated git, then you don't need to do this. You will be informed at the beginning if you have already initialized Git.
If you have not yet initialized Git, you can do so with:
git init
If you already have a project set up in Git and prefer to clone, then other steps are required. For more information when to use git init
, see this guide.
#
Step 2: Install husky
After initializing the git repository you can add husky to your project by running the following command:
rocket launchpad husky
Link to the husky documentation
#
More information
Husky is used to verify that code consistency rules are followed before committing. For more information click here.
We create 1 hooks with husky:
commit-msg
In this step we also add commitlint.
This has the background that we immediately connect a hook to Git that is based on commitlint
You do not need to install commitlint yourself when you install husky. You also do not need to set a hook for Git, it will be done automatically.
#
commit-msg
The commit-msg hook is used to check the commit message. If the commit message does not comply with the code consistency rules, the commit will be rejected.
When using semantic-release, we recommend that you disable husky for the semantic-release run.
In /.github/workflows/create-semantic-release.yml
you can add following line to prevent husky from running when semantic-release is running, so you don't run into problems later on:
env:
HUSKY: 0