-
Install and save Husky as a dev dependency:
npm install --save-dev husky
-
Add this repository as a submodule in the
.husky
directory:git submodule add [email protected]:shardeum/git-hooks .husky
-
Initialize Husky:
npx husky init
You will notice that husky has added or modified the
prepare
script inpackage.json
. If it was modified, you can add the oldprepare
script back as apostprepare
script, e.g.{ // ... "prepare": "husky", "postprepare": "npm run compile", // ... }
-
Modify the
prepare
script inpackage.json
to automatically initialize this submodule for other developers:{ // ... "prepare": "git submodule update --init && husky", // ... }
Husky will install hooks automatically when developers run
npm install
.
Important
Don't skip this last step! Developers will have to manually clone or initialize hooks otherwise, and hooks won't be executed until they do.
Hooks are installed via this submodule method in order to more easily and effectively propagate changes to other repositories. If updates are made to the hooks in this repository, they can be pulled and updated in other repositories by updating the submodule:
git submodule update --remote
Important
Remember to git add .husky && git commit
the update!