Skip to content
Back to skills

Installing Git Hooks

ASecurity

Use when setting up git pre-commit and pre-push hooks - provides simple shell script approach and pre-commit framework method, both calling justfile commands for DRY principle

  • 666 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added February 9, 2026
developmentpythongoshellbashgitapi

Works with

  • api

Security analysis

A96/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned February 12, 2026

npx -y skills add majiayu000/claude-skill-registry --skill installing-git-hooks --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Installing Git Hooks?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Installing Git Hooks
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-installing-git-hooks/badge)](https://www.skillsdirectory.com/skills/majiayu000-installing-git-hooks)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: installing-git-hooks
description: Use when setting up git pre-commit and pre-push hooks - provides simple shell script approach and pre-commit framework method, both calling justfile commands for DRY principle
---

# Installing Git Hooks

## Purpose

Enforce quality checks automatically:
- **Pre-commit:** format, lint, typecheck
- **Pre-push:** test

Hooks call justfile commands (DRY).

## Quick Setup

```bash
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/bash
set -e
echo "Running pre-commit checks..."
just format
just lint
just typecheck
echo "✅ Pre-commit checks passed"
EOF
chmod +x .git/hooks/pre-commit

cat > .git/hooks/pre-push << 'EOF'
#!/bin/bash
set -e
echo "Running pre-push checks..."
just test
echo "✅ Pre-push checks passed"
EOF
chmod +x .git/hooks/pre-push
```

## Justfile Integration

```just
# Install git hooks
hooks:
    @echo "Installing git hooks..."
    @cat > .git/hooks/pre-commit << 'EOF'\n#!/bin/bash\nset -e\necho "Running pre-commit checks..."\njust format\njust lint\njust typecheck\necho "✅ Pre-commit checks passed"\nEOF
    @chmod +x .git/hooks/pre-commit
    @cat > .git/hooks/pre-push << 'EOF'\n#!/bin/bash\nset -e\necho "Running pre-push checks..."\njust test\necho "✅ Pre-push checks passed"\nEOF
    @chmod +x .git/hooks/pre-push
    @echo "✅ Git hooks installed"

hooks-remove:
    rm -f .git/hooks/pre-commit .git/hooks/pre-push
    @echo "✅ Git hooks removed"
```

## Pre-commit Framework

For teams or complex setups:

**`.pre-commit-config.yaml`:**
```yaml
repos:
  - repo: local
    hooks:
      - id: format
        name: Format code
        entry: just format
        language: system
        pass_filenames: false

      - id: lint
        name: Lint code
        entry: just lint
        language: system
        pass_filenames: false

      - id: typecheck
        name: Type check
        entry: just typecheck
        language: system
        pass_filenames: false

      - id: test
        name: Run tests
        entry: just test
        language: system
        pass_filenames: false
        stages: [push]
```

**Install:**
```bash
pip install pre-commit
pre-commit install
pre-commit install --hook-type pre-push
```

## Python with venv

```bash
#!/bin/bash
set -e
source .venv/bin/activate
just format
just lint
just typecheck
```

## Polyglot Projects

```bash
#!/bin/bash
set -e

if git diff --cached --name-only | grep -q "^api/"; then
    cd api && just format && just lint && just typecheck
fi

if git diff --cached --name-only | grep -q "^web/"; then
    cd web && just format && just lint && just typecheck
fi
```

## Best Practices

- **Fast:** Format/lint/typecheck in seconds
- **Fail fast:** Use `set -e` to exit on first error
- **Match CI:** Hooks should match CI checks
- **Document:** Include setup in README/onboarding

## Skipping (Use Sparingly)

```bash
git commit --no-verify -m "message"  # Skip pre-commit
git push --no-verify                 # Skip pre-push
```

## Troubleshooting

**Hook not running:**
```bash
ls -la .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit
head -1 .git/hooks/pre-commit  # Verify shebang
```

**Just not found:**
```bash
#!/bin/bash
export PATH="$HOME/.cargo/bin:$PATH"
set -e
just format
```

**Venv issues:**
```bash
#!/bin/bash
set -e
source .venv/bin/activate
just format
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.