Implement Git hooks using Husky, pre-commit, and custom scripts. Enforce code quality, linting, and testing before commits and pushes.
Configure Git hooks to enforce code quality standards, run automated checks, and prevent problematic commits from being pushed to shared repositories.
Minimal working example:
#!/bin/bash
# setup-husky.sh
# Install Husky
npm install husky --save-dev
# Initialize Husky
npx husky install
# Create pre-commit hook
npx husky add .husky/pre-commit "npm run lint"
# Create commit-msg hook
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
# Create pre-push hook
npx husky add .husky/pre-push "npm run test"
# Create post-merge hook
npx husky add .husky/post-merge "npm install"
Detailed implementations in the references/ directory:
| Guide | Contents | |---|---| | Husky Installation and Configuration | Husky Installation and Configuration | | Pre-commit Hook (Node.js) | Pre-commit Hook (Node.js) | | Commit Message Validation | Commit Message Validation | | Commitlint Configuration | Commitlint Configuration, Pre-push Hook (Comprehensive) | | Pre-commit Framework (Python) | Pre-commit Framework (Python) | | Secret Detection Hook | Secret Detection Hook, Husky in package.json |
--no-verify (rarely)--no-verifyCopy a source-pinned command for your client. You run it yourself.
Destination: .claude/skills/git-hooks-setup · pinned to the source commit
git clone https://github.com/aj-geddes/useful-ai-prompts.git
cd useful-ai-prompts
git checkout 3f5182cfd739fc113f4af5244a1cf342ad7f7911
mkdir -p ".claude/skills/git-hooks-setup"
cp -r "skills/git-hooks-setup" ".claude/skills/git-hooks-setup"Review the source before running. This copies files into your project; it is not a one-click install and does not verify runtime safety.
Scanner static-checks@0.1.0 · commit 3f5182cfd739. Static checks cannot prove runtime safety – review the source and the exact diff before installing. How checks work.
Instructs shell/process/package operations that run commands on the host.
Evidence: npm install· fingerprint 3a2dc0ae21eb56d7