Sharing Hooks with Husky
Learn how to share Git hooks across a team using Husky so everyone runs the same checks automatically.
Sharing Hooks with Husky is a free DevOps Bootcamp lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
The Problem with Native Hooks
Native Git hooks live in .git/hooks, which is not committed to the repository. That means teammates do not get your hooks automatically.
What is Husky?
Husky is a popular tool that stores hooks inside the repo and installs them for everyone, so the whole team runs the same checks.
Installing Husky
Add Husky as a dev dependency in a Node.js project.
npm install --save-dev huskyInitializing Husky
The init command sets up the .husky directory and configures Git to use it.
npx husky initHow Husky Redirects Hooks
Husky points Git's core.hooksPath to the committed .husky folder instead of .git/hooks.
git config core.hooksPath .huskyAdding a Pre-commit Hook
Create a .husky/pre-commit file that runs your lint or test command before each commit.
echo 'npm test' > .husky/pre-commitCommitting the Hook
Because .husky is inside the repo, you commit it like any other file. Teammates get it on their next pull.
git add .husky/pre-commit
git commit -m 'Add pre-commit test hook'Running Linters on Staged Files
Pair Husky with lint-staged to only check files you actually staged, keeping commits fast.
npm install --save-dev lint-stagedConfiguring lint-staged
Define which command runs on which files in package.json.
{
'lint-staged': {
'*.js': 'eslint --fix'
}
}A commit-msg Hook
Husky can also enforce commit message rules using a commit-msg hook with a tool like commitlint.
echo 'npx commitlint --edit $1' > .husky/commit-msgBypassing Hooks When Needed
In emergencies you can skip hooks with --no-verify, though it should be rare.
git commit --no-verify -m 'WIP'Quick Check
Test your understanding of sharing hooks with Husky.
Recap
You learned to share hooks with Husky:
- Native hooks in
.git/hooksare not shared - Husky stores hooks in a committed
.huskyfolder - It redirects
core.hooksPath - Pair with lint-staged and commitlint for team-wide checks
Frequently asked questions
Is the “Sharing Hooks with Husky” lesson free?
Yes — the full text of “Sharing Hooks with Husky” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.
What will I learn in “Sharing Hooks with Husky”?
Learn how to share Git hooks across a team using Husky so everyone runs the same checks automatically. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Sharing Hooks with Husky” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Understanding Git Hooks
- Pre-commit & Post-merge Hooks
- Customizing Git Configuration
- Sharing Hooks with Husky