Since Git 2.54.0, you can now setup your hooks in local git config. This allows to easily configure and share hooks with your team, without a third party helper to setup. In this article, I share how I set it up and how I replace Husky with it.
How to setup
[hook "lint-commit"]
event = pre-commit
command = yarn commitlint \${1}
First, create a .gitconfig in your repository. Add the config of your choice. Then, tell git where your config is:
git config set --local include.path ../.gitconfig
The path is relative to your .git/config file. Running this command edits it to add:
[include]
path = ../.gitconfig
How to remove Husky
Husky was a great tool to share hooks until now. Now, it's not needed anymore. Here are the steps to remove:
- remove reference from your local git config
- remove the dependency from package.json
- replace husky setup command with git's
Here are the commands to run:
# This should return your local husky folder. In my case, it was `.husky`
git config --local core.hooksPath
# To remove it
git config --local --unset core.hooksPath
yarn remove husky
In my package.json, I used to have yarn run postinstall to run husky. Now I replaced it with git config set --local include.path ../.gitconfig. New contributor can also benefit from the hooks.