Run quality checks automatically with Git hooks
8 steps · about 1 h 55 min · Beginner
- How Git hooks work (tutorial, Atlassian Git tutorials, 15 min)
See where hook scripts live, which events trigger them and why they are not copied when someone clones.
- The hook reference (reference, Git documentation, 15 min)
Look up the exact inputs and exit-code rules for pre-commit, commit-msg and pre-push before writing one.
- Share hooks with the pre-commit framework (doc, pre-commit, 20 min)
Install a language-neutral hook manager and pin hook versions in a file the whole team commits.
- Choose ready-made hooks (reference, pre-commit, 10 min)
Pick existing hooks for whitespace, large files, secrets and formatters instead of writing scripts.
- Set up hooks in a JavaScript project with Husky (doc, Husky, 10 min)
In npm-based projects, install hooks automatically for every developer on install.
- Check only the files being committed (repo, lint-staged, 15 min)
Run linters and formatters on staged files so the hook stays fast enough that nobody disables it.
- Enforce a commit message convention (doc, commitlint, 15 min)
Add a commit-msg check so history stays readable and release tools can parse it.
- Back hooks up with required checks on the server (doc, GitHub Docs, 15 min)
Anyone can skip a local hook, so require the same checks in CI before merging to the main branch.