git-advanced-6-git-hooks
Sub-skill of git-advanced: 6. Git Hooks.
Best use case
git-advanced-6-git-hooks is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Sub-skill of git-advanced: 6. Git Hooks.
Teams using git-advanced-6-git-hooks should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/6-git-hooks/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How git-advanced-6-git-hooks Compares
| Feature / Agent | git-advanced-6-git-hooks | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Sub-skill of git-advanced: 6. Git Hooks.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 6. Git Hooks
## 6. Git Hooks
**Available Hooks:**
```
client-side:
pre-commit # Before commit message prompt
prepare-commit-msg # Edit default message
commit-msg # Validate commit message
post-commit # After commit completes
pre-push # Before push
server-side:
pre-receive # Before accepting push
update # Per-branch check
post-receive # After push completes
```
**Pre-commit Hook Example:**
```bash
#!/bin/bash
# .git/hooks/pre-commit
# ABOUTME: Pre-commit hook for code quality
# ABOUTME: Runs linting and tests before commit
set -e
echo "Running pre-commit checks..."
# Check for debug statements
if git diff --cached --name-only | xargs grep -l 'console.log\|debugger\|binding.pry' 2>/dev/null; then
echo "ERROR: Debug statements found. Remove before committing."
exit 1
fi
# Run linter
if [ -f "package.json" ] && grep -q '"lint"' package.json; then
echo "Running linter..."
npm run lint --quiet || exit 1
fi
# Run tests
if [ -f "package.json" ] && grep -q '"test"' package.json; then
echo "Running tests..."
npm test --quiet || exit 1
fi
echo "Pre-commit checks passed!"
```
**Commit-msg Hook Example:**
```bash
#!/bin/bash
# .git/hooks/commit-msg
# ABOUTME: Validates commit message format
# ABOUTME: Enforces conventional commits
COMMIT_MSG_FILE="$1"
COMMIT_MSG=$(cat "$COMMIT_MSG_FILE")
# Conventional commit pattern
PATTERN="^(feat|fix|docs|style|refactor|test|chore|perf|ci|build|revert)(\(.+\))?: .{1,50}"
if ! echo "$COMMIT_MSG" | grep -qE "$PATTERN"; then
echo "ERROR: Invalid commit message format."
echo ""
echo "Expected format: <type>(<scope>): <subject>"
echo "Types: feat, fix, docs, style, refactor, test, chore, perf, ci, build, revert"
echo ""
echo "Examples:"
echo " feat(auth): add login functionality"
echo " fix(api): handle null response"
echo " docs: update README"
exit 1
fi
```
**Pre-push Hook Example:**
```bash
#!/bin/bash
# .git/hooks/pre-push
# ABOUTME: Pre-push hook for safety checks
# ABOUTME: Prevents pushing to protected branches
BRANCH=$(git rev-parse --abbrev-ref HEAD)
PROTECTED_BRANCHES="^(main|master|production)$"
if echo "$BRANCH" | grep -qE "$PROTECTED_BRANCHES"; then
echo "ERROR: Direct push to $BRANCH is not allowed."
echo "Please create a pull request instead."
exit 1
fi
# Run full test suite before push
echo "Running tests before push..."
npm test || exit 1
echo "Pre-push checks passed!"
```
**Using pre-commit Framework:**
```yaml
# .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-json
- id: check-merge-conflict
- id: detect-private-key
- repo: https://github.com/psf/black
rev: 24.1.0
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.0.0
hooks:
- id: flake8
- repo: local
hooks:
- id: run-tests
name: Run tests
entry: npm test
language: system
pass_filenames: false
always_run: true
```
**Install pre-commit hooks:**
```bash
# Install pre-commit
pip install pre-commit
# Install hooks
pre-commit install
# Install commit-msg hook
pre-commit install --hook-type commit-msg
# Run manually
pre-commit run --all-files
```Related Skills
skill-creator-advanced-usage
Sub-skill of skill-creator: Advanced Usage.
git-advanced-9-monorepo-patterns
Sub-skill of git-advanced: 9. Monorepo Patterns.
git-advanced-7-git-aliases
Sub-skill of git-advanced: 7. Git Aliases (+1).
git-advanced-3-git-bisect
Sub-skill of git-advanced: 3. Git Bisect (+2).
git-advanced-1-interactive-rebase
Sub-skill of git-advanced: 1. Interactive Rebase (+1).
git-advanced-1-complete-gitconfig
Sub-skill of git-advanced: 1. Complete .gitconfig (+2).
git-advanced-1-commit-history
Sub-skill of git-advanced: 1. Commit History (+2).
airflow-2-advanced-operators
Sub-skill of airflow: 2. Advanced Operators (+6).
devtools-git-advanced-workflows
Sub-skill of devtools: Git Advanced Workflows (+1).
pandoc-integration-with-git-hooks
Sub-skill of pandoc: Integration with Git Hooks (+1).
python-pptx-2-advanced-text-formatting
Sub-skill of python-pptx: 2. Advanced Text Formatting.
python-docx-2-advanced-paragraph-formatting
Sub-skill of python-docx: 2. Advanced Paragraph Formatting.