Git Hooks Setup

aj-geddes/useful-ai-prompts/skills/git-hooks-setup

by aj-geddes3f5182cfd739No license355 starsListed Oct 8, 2026Updated Oct 8, 2026Repository updated 7 months ago

Implement Git hooks using Husky, pre-commit, and custom scripts. Enforce code quality, linting, and testing before commits and pushes.

AI-generated overview

Sets up Git hooks with Husky, pre-commit, and custom scripts to enforce code quality before commits and pushes.

What it does
This skill guides the configuration of Git hooks that run automated checks before commits and pushes. It covers Husky installation, pre-commit hooks for Node.js and Python, commit message validation with commitlint, secret detection, and pre-push test runs. It ships reference guides, a test scaffolding script, and a test template.
When to use it
Use it when adding pre-commit linting, formatting, or secret scanning to a repository, validating commit message conventions, or running tests before push. It suits teams wanting consistent, shared code quality standards enforced through Git hooks.
Requirements
Requires Git and a Node.js/npm environment for Husky and commitlint, or Python with the pre-commit framework for Python projects. It ships executable scripts (scripts/scaffold-tests.sh) and a template (templates/test-template.js).

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

  • Pre-commit code quality checks
  • Commit message validation
  • Preventing secrets in commits
  • Running tests before push
  • Code formatting enforcement
  • Linting configuration
  • Team-wide standards enforcement

Quick Start

Minimal working example:

bash
#!/bin/bash# setup-husky.sh
# Install Huskynpm install husky --save-dev
# Initialize Huskynpx husky install
# Create pre-commit hooknpx husky add .husky/pre-commit "npm run lint"
# Create commit-msg hooknpx husky add .husky/commit-msg 'npx --no -- commitlint --edit "$1"'
# Create pre-push hooknpx husky add .husky/pre-push "npm run test"
# Create post-merge hooknpx husky add .husky/post-merge "npm install"

Reference Guides

Detailed implementations in the references/ directory:

GuideContents
Husky Installation and Configuration [blocked]Husky Installation and Configuration
Pre-commit Hook (Node.js) [blocked]Pre-commit Hook (Node.js)
Commit Message Validation [blocked]Commit Message Validation
Commitlint Configuration [blocked]Commitlint Configuration, Pre-push Hook (Comprehensive)
Pre-commit Framework (Python) [blocked]Pre-commit Framework (Python)
Secret Detection Hook [blocked]Secret Detection Hook, Husky in package.json

Best Practices

✅ DO

  • Enforce pre-commit linting and formatting
  • Validate commit message format
  • Scan for secrets before commit
  • Run tests on pre-push
  • Skip hooks only with --no-verify (rarely)
  • Document hook requirements in README
  • Use consistent hook configuration
  • Make hooks fast (< 5 seconds)
  • Provide helpful error messages
  • Allow developers to bypass with clear warnings

❌ DON'T

  • Skip checks with --no-verify
  • Store secrets in committed files
  • Use inconsistent implementations
  • Ignore hook errors
  • Run full test suite on pre-commit

Source and attribution

Source:aj-geddes/useful-ai-promptsinskills/git-hooks-setupat commit3f5182c

License: No license

Content belongs to its original authors. SourceWeft indexes it from a public repository.

Report or request removal