Git hooks setup

From aj-geddes/useful-ai-prompts · View interactive version

Git hooks setup is an AI agent skill from the GitHub repository aj-geddes/useful-ai-prompts. Implement Git hooks using Husky, pre-commit, and custom scripts. Enforce code quality, linting, and testing before commits and pushes.

How to use this skill

Skill file

Git Hooks Setup

Table of Contents

Overview

Configure Git hooks to enforce code quality standards, run automated checks, and prevent problematic commits from being pushed to shared repositories.

When to Use

Quick Start

Minimal working example:

#!/bin/bash
# setup-husky.sh

# Install Husky
npm install husky --save-dev

# Initialize Husky
npx husky install

# Create pre-commit hook
npx husky add .husky/pre-commit "npm run lint"

# Create commit-msg hook
npx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'

# Create pre-push hook
npx husky add .husky/pre-push "npm run test"

# Create post-merge hook
npx husky add .husky/post-merge "npm install"

Reference Guides

Detailed implementations in the references/ directory:

| Guide | Contents |

|---|---|

| Husky Installation and Configuration | Husky Installation and Configuration |

| Pre-commit Hook (Node.js) | Pre-commit Hook (Node.js) |

| Commit Message Validation | Commit Message Validation |

| Commitlint Configuration | Commitlint Configuration, Pre-push Hook (Comprehensive) |

| Pre-commit Framework (Python) | Pre-commit Framework (Python) |

| Secret Detection Hook | Secret Detection Hook, Husky in package.json |

Best Practices

✅ DO

❌ DON'T

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.