git-hooks
Auto-generate and manage Git hooks for pre-commit, pre-push, commit-msg, and more.
- License 许可
- MIT
- 最近更新
- 2026-08-23
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- description
- Auto-generate and manage Git hooks for pre-commit, pre-push, commit-msg, and more.
02 资源文件 2
- 参考文档_meta.json270 B
- 参考文档README.md425 B
03 SKILL.md 正文
Git Hooks
Set up and manage Git hooks for any repository.
Use when adding automated checks to git workflows — linting, testing, commit message validation.
Requirements
- Git repository (
.git/directory must exist) - No API keys needed
Instructions
-
Verify repo root:
test -d .git && echo "OK" || echo "Not a git repo". Never create hooks outside a git repo. -
Back up existing hooks before overwriting:
[ -f .git/hooks/pre-commit ] && cp .git/hooks/pre-commit .git/hooks/pre-commit.bak -
Create the hook and make it executable:
cat > .git/hooks/<hook-name> << 'EOF' #!/bin/sh # hook content here EOF chmod +x .git/hooks/<hook-name>
Common Hooks
Pre-commit: Lint Staged Files
#!/bin/sh
STAGED=$(git diff --cached --name-only --diff-filter=ACM)
# JavaScript/TypeScript
echo "$STAGED" | grep -E '\.(js|ts|jsx|tsx)$' | xargs -r npx eslint --quiet 2>/dev/null
[ $? -ne 0 ] && echo "❌ ESLint failed" && exit 1
# Python
echo "$STAGED" | grep -E '\.py$' | xargs -r python3 -m py_compile 2>&1
[ $? -ne 0 ] && echo "❌ Python syntax check failed" && exit 1
exit 0
Pre-push: Run Tests
#!/bin/sh
[ -f package.json ] && npm test
[ -f pytest.ini ] || [ -d tests/ ] && python3 -m pytest -q
exit $?
Commit-msg: Enforce Conventional Commits
#!/bin/sh
MSG=$(cat "$1")
if ! echo "$MSG" | grep -qE '^(feat|fix|docs|style|refactor|test|chore|ci|perf|build)(\(.+\))?: .+'; then
echo "❌ Commit message must follow Conventional Commits format"
echo " Example: feat(auth): add login page"
exit 1
fi
Pre-commit: Prevent Secret Leaks
#!/bin/sh
STAGED=$(git diff --cached --diff-filter=ACM -p)
if echo "$STAGED" | grep -qEi '(api[_-]?key|secret|password|token)\s*[=:]\s*["\x27][^\s]+'; then
echo "❌ Potential secret detected in staged changes!"
echo " Review your changes and use environment variables instead."
exit 1
fi
Management Commands
# List active hooks (non-sample)
ls .git/hooks/ | grep -v '\.sample$'
# Disable a hook temporarily
chmod -x .git/hooks/pre-commit
# Re-enable
chmod +x .git/hooks/pre-commit
# Remove a hook
rm .git/hooks/pre-commit
Edge Cases & Troubleshooting
- Hook not running: Check
chmod +xand shebang line (#!/bin/shor#!/bin/bash). - Bypass when needed:
git commit --no-verifyskips pre-commit and commit-msg hooks. - Team sharing: Hooks in
.git/hooks/aren't committed. Use ahooks/directory in repo root +git config core.hooksPath hooks/for team-wide hooks. - Windows compatibility: Use
#!/bin/sh(not bash) for cross-platform support. Avoid bash-specific syntax. - Slow hooks: Keep pre-commit hooks under 5 seconds. Only lint staged files, not the whole project.
Security Considerations
- Add a secret-detection hook (see above) to prevent accidental credential commits.
- Never store API keys or passwords in hook scripts themselves.
04 同仓库更多 Skills
crowd-prompting
A marketplace where AI agents improve prompts, system instructions, tool descriptions, and other text-based content with domain expertise from real-world operations — and earn tokens for valuable contributions.
dilemm-ai
Compete in DilemmAI, the prisoner's dilemma AI arena at dilemm.ai. Use when an OpenClaw agent wants to create an account, design and submit strategy prompts for their bot, enter matchmaking, analyze historical matches and leaderboards, and iterate on bot strategy. Requires headless browser automation (no API available yet).
arxiv-paper-reviews
Interact with arXiv Crawler API to fetch papers, read reviews, and submit comments. Use when working with arXiv papers, fetching paper lists by date/category/interest, viewing paper details with comments, or submitting paper reviews via API at http://150.158.152.82:8000.
arxiv-paper-reviews
Interact with arXiv Crawler API to fetch papers, read reviews, and submit comments. Use when working with arXiv papers, fetching paper lists by date/category/interest, viewing paper details with comments, or submitting paper reviews via API at http://150.158.152.82:8000.
git-summary
Get a quick summary of the current Git repository including status, recent commits, branches, and contributors.
agent-constitution
Interact with AgentConstitution governance contracts on Base Sepolia. Check compliance, read rules, log actions, query governance state.