Skip to content
Back to skills

Git Hooks

ASecurity

Git hooks setup with pre-commit, husky, and lint-staged for automated code quality. Use when user asks to "setup pre-commit hooks", "add husky", "lint on commit", "format before commit", "run tests on push", "setup git hooks", or automate code quality checks.

  • 225 stars
  • 0 votes
  • 0 copies
  • 5 views
  • Added September 4, 2026
testingpythonbashnodegit

Security analysis

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

Pro scans all 13 files and shows the line behind each finding

Scanned September 4, 2026

npx -y skills add NeverSight/skills_feed --skill git-hooks --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Git Hooks?

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

Security grade badge for Git Hooks
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/neversight-git-hooks/badge)](https://www.skillsdirectory.com/skills/neversight-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: git-hooks
description: Git hooks setup with pre-commit, husky, and lint-staged for automated code quality. Use when user asks to "setup pre-commit hooks", "add husky", "lint on commit", "format before commit", "run tests on push", "setup git hooks", or automate code quality checks.
---

# Git Hooks

Automate code quality with Git hooks using pre-commit, Husky, or native hooks.

## Husky + lint-staged (Node.js Projects)

### Setup

```bash
# Install
npm install -D husky lint-staged

# Initialize husky
npx husky init

# This creates .husky/pre-commit
```

### Configure lint-staged

```json
// package.json
{
  "lint-staged": {
    "*.{js,jsx,ts,tsx}": [
      "eslint --fix",
      "prettier --write"
    ],
    "*.{json,md,yml}": "prettier --write",
    "*.css": ["stylelint --fix", "prettier --write"]
  }
}
```

### Pre-commit Hook

```bash
# .husky/pre-commit
npx lint-staged
```

### Pre-push Hook

```bash
# Create hook
echo "npm test" > .husky/pre-push
chmod +x .husky/pre-push
```

## Pre-commit Framework (Python/Polyglot)

### Setup

```bash
pip install pre-commit
pre-commit install
```

### Configuration

```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-added-large-files

  - repo: https://github.com/psf/black
    rev: 24.1.0
    hooks:
      - id: black

  - repo: https://github.com/astral-sh/ruff-pre-commit
    rev: v0.1.14
    hooks:
      - id: ruff
        args: [--fix]

  - repo: https://github.com/pre-commit/mirrors-mypy
    rev: v1.8.0
    hooks:
      - id: mypy

  - repo: local
    hooks:
      - id: pytest
        name: pytest
        entry: pytest
        language: system
        pass_filenames: false
        always_run: true
        stages: [push]
```

### Commands

```bash
pre-commit run --all-files  # Run on all files
pre-commit autoupdate       # Update hook versions
pre-commit install --hook-type pre-push
```

## Native Git Hooks

### Hook Locations

```
.git/hooks/
├── pre-commit      # Before commit
├── prepare-commit-msg  # Edit commit message
├── commit-msg      # Validate commit message
├── pre-push        # Before push
├── pre-rebase      # Before rebase
└── post-merge      # After merge
```

### Simple Pre-commit

```bash
#!/bin/sh
# .git/hooks/pre-commit

# Run linter
npm run lint
if [ $? -ne 0 ]; then
  echo "Lint failed. Commit aborted."
  exit 1
fi

# Run tests
npm test
if [ $? -ne 0 ]; then
  echo "Tests failed. Commit aborted."
  exit 1
fi
```

### Commit Message Validation

```bash
#!/bin/sh
# .git/hooks/commit-msg

commit_msg=$(cat "$1")

# Conventional commits pattern
pattern="^(feat|fix|docs|style|refactor|test|chore)(\(.+\))?: .{1,50}"

if ! echo "$commit_msg" | grep -qE "$pattern"; then
  echo "Invalid commit message format."
  echo "Use: type(scope): description"
  exit 1
fi
```

## Sharing Hooks

### Git Config (core.hooksPath)

```bash
# Store hooks in repo
mkdir .githooks
mv .git/hooks/* .githooks/

# Configure git to use them
git config core.hooksPath .githooks
```

### Team Setup

```json
// package.json
{
  "scripts": {
    "prepare": "husky || true"
  }
}
```

## Skip Hooks (Emergency)

```bash
git commit --no-verify -m "Emergency fix"
git push --no-verify
```

Files in this skill

  • SKILL.md3.3 KB
  • description_ar.txt629 B
  • description_cn.txt319 B
  • description_de.txt366 B
  • description_en.txt260 B
  • description_es.txt373 B
  • description_fr.txt408 B
  • description_it.txt349 B
  • description_ja.txt534 B
  • description_ko.txt347 B
  • description_ru.txt700 B
  • description_tw.txt334 B
  • stats.json65 B

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.

View all in testing →

Comments

Loading comments…

Newsletter

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