Git Hooks Toolkit
Install production-ready Git hooks in seconds with pre-built templates.
Quick Start
CODEBLOCK0
Available Templates
pre-commit
- - lint-staged — Run ESLint/Ruff/Flake8 on staged files only
- no-debug — Block console.log, debugger, pdb, breakpoint()
- large-files — Prevent files over 500KB from being committed
- format-check — Auto-run Prettier, Black, gofmt on staged files
commit-msg
- - conventional — Enforce Conventional Commits (feat/fix/docs/etc.)
- ticket-ref — Require ticket reference (#123, PROJ-456)
- no-wip — Block WIP commits on main/master/release branches
pre-push
- - run-tests — Auto-detect project type and run test suite
- branch-protect — Prevent direct push to main/master
post-merge
- - install-deps — Auto-install deps when lockfiles change
Commands
- -
list — Show all templates - INLINECODE1 — Install a hook
- INLINECODE2 — Preview template content
- INLINECODE3 — Show installed hooks
- INLINECODE4 — Delete a hook
Git Hooks 工具包
使用预构建模板,在数秒内安装生产就绪的 Git 钩子。
快速开始
bash
列出所有可用模板
python3 scripts/git_hooks.py list
安装钩子
python3 scripts/git_hooks.py install pre-commit lint-staged
python3 scripts/git_hooks.py install commit-msg conventional
安装前预览
python3 scripts/git_hooks.py show pre-commit no-debug
检查已安装内容
python3 scripts/git_hooks.py status
移除钩子
python3 scripts/git_hooks.py remove pre-commit
可用模板
pre-commit(提交前)
- - lint-staged — 仅对暂存文件运行 ESLint/Ruff/Flake8
- no-debug — 阻止 console.log、debugger、pdb、breakpoint()
- large-files — 阻止提交超过 500KB 的文件
- format-check — 自动对暂存文件运行 Prettier、Black、gofmt
commit-msg(提交信息)
- - conventional — 强制使用约定式提交(feat/fix/docs 等)
- ticket-ref — 要求包含工单引用(#123、PROJ-456)
- no-wip — 阻止在 main/master/release 分支上提交 WIP
pre-push(推送前)
- - run-tests — 自动检测项目类型并运行测试套件
- branch-protect — 阻止直接推送到 main/master 分支
post-merge(合并后)
- - install-deps — 当锁定文件发生变化时自动安装依赖
命令
- - list — 显示所有模板
- install <钩子> <模板> [--repo 路径] [--force] — 安装钩子
- show <钩子> <模板> — 预览模板内容
- status [--repo 路径] — 显示已安装的钩子
- remove <钩子> [--repo 路径] — 删除钩子