@mazhu/githooks
v1.0.0
Published
Simple Git hooks manager with sharing and reuse support
Maintainers
Readme
@mazhu/githooks
Simple Git hooks manager with sharing and reuse support
Features
- 🚀 Easy Git hooks management — init, add, list, run, install
- 📦 Built-in hook templates — lint-staged, commit-msg, pre-push
- 🔄 Share and reuse hooks across projects
- ⚡ Zero dependencies (except commander.js)
- 🎨 Colored output for better readability
Quick Start
# Install globally
npm install -g @mazhu/githooks
# Initialize in your project
cd your-project
githooks init
# Add a built-in hook
githooks add lint-staged --builtin lint-staged
# Add a custom hook
githooks add my-check --type pre-commit --command "npm run lint"
# List all hooks
githooks list
# Manually run a hook
githooks run my-check
# Install hooks to .git/hooks
githooks install
# Export a hook for sharing
githooks share my-check -o my-check.hook.jsonCommands
githooks init
Initialize .githooks directory in the current project. Creates:
.githooks/githooks.json— Configuration file- Adds
.githooks/to.gitignore
githooks add <name>
Add a new hook. Options:
-t, --type <type>— Hook type (pre-commit, commit-msg, pre-push, etc.)-c, --command <cmd>— Command to run in the hook--builtin <name>— Use a built-in hook template
# Using a built-in template
githooks add lint --builtin lint-staged
# Custom hook
githooks add test --type pre-push --command "npm test"githooks list
List all configured hooks with their type, command, and status.
githooks run <name>
Manually run a hook by name. Useful for testing before installing.
githooks install
Install all enabled hooks to .git/hooks. Options:
-f, --force— Force overwrite existing hooks
githooks share <name>
Export a hook as a JSON file for sharing. Options:
-o, --output <path>— Output file path (default:./<name>.hook.json)
Built-in Hooks
| Name | Type | Command | Description |
|------|------|---------|-------------|
| lint-staged | pre-commit | npx lint-staged | Run linters on staged files |
| commit-msg | commit-msg | npx commitlint --edit $1 | Validate commit messages |
| pre-push | pre-push | npm test | Run tests before pushing |
Configuration
Hooks are stored in .githooks/githooks.json:
{
"version": "1.0.0",
"hooks": {
"lint": {
"type": "pre-commit",
"command": "npx lint-staged",
"enabled": true
},
"test": {
"type": "pre-push",
"command": "npm test",
"enabled": true
}
}
}Hook Types
All standard Git hook types are supported:
pre-commit, commit-msg, pre-push, pre-rebase, prepare-commit-msg, post-commit, post-checkout, post-merge, post-rewrite, pre-applypatch, applypatch-msg, and more.
License
MIT © mazhu
