Langsung ke konten
Skillpedia
Deploy & cloud (DevOps)48k Β· #4735

git-hooks-automation

Fungsinya

Mengotomatiskan pemeriksaan kualitas kode sebelum Anda melakukan commit perubahan. Alat ini memastikan kode Anda terformat dengan rapi, bebas dari error, dan memiliki pesan commit yang terstandar, semuanya sebelum kode masuk ke sistem utama.

Kapan dipakai

  • βœ“Menyiapkan alat seperti Husky atau pre-commit.
  • βœ“Memastikan pesan commit mengikuti standar.
  • βœ“Mengotomatiskan format kode dan pengecekan error.

Link skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/git-hooks-automation/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/git-hooks-automation/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œAtur pre-commit hook untuk memformat dan melakukan lint pada kode saya.”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Alat ini menggunakan tools seperti Husky dan lint-staged untuk menjalankan script secara otomatis. Script tersebut memeriksa kode Anda dari error dan masalah format sebelum Anda diizinkan melakukan commit atau push perubahan.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

Git Hooks Automation

Automate code quality enforcement at the Git level. Set up hooks that lint, format, test, and validate before commits and pushes ever reach your CI pipeline β€” catching issues in seconds instead of minutes.

When to Use This Skill

  • User asks to "set up git hooks" or "add pre-commit hooks"
  • Configuring Husky, lint-staged, or the pre-commit framework
  • Enforcing commit message conventions (Conventional Commits, commitlint)
  • Automating linting, formatting, or type-checking before commits
  • Setting up pre-push hooks for test runners
  • Migrating from Husky v4 to v9+ or adopting hooks from scratch
  • User mentions "pre-commit", "commit-msg", "pre-push", "lint-staged", or "githooks"

Git Hooks Fundamentals

Git hooks are scripts that run automatically at specific points in the Git workflow. They live in .git/hooks/ and are not version-controlled by default β€” which is why tools like Husky exist.

Hook Types & When They Fire

Hook Fires When Common Use
pre-commit Before commit is created Lint, format, type-check staged files
prepare-commit-msg After default msg, before editor Auto-populate commit templates
commit-msg After user writes commit message Enforce commit message format
post-commit After commit is created Notifications, logging
pre-push Before push to remote Run tests, check branch policies
pre-rebase Before rebase starts Prevent rebase on protected branches
post-merge After merge completes Install deps, run migrations
post-checkout After checkout/switch Install deps, rebuild assets

Native Git Hooks (No Framework)

# Create a pre-commit hook manually
cat > .git/hooks/pre-commit << 'EOF'
#!/bin/sh
set -e

# Run linter on staged files only
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(js|ts|jsx|tsx)$' || true)

if [ -n "$STAGED_FILES" ]; then
  echo "πŸ” Linting staged files..."
  echo "$STAGED_FILES" | xargs npx eslint --fix
  echo "$STAGED_FILES" | xargs git add  # Re-stage after fixes
fi
EOF
chmod +x .git/hooks/pre-commit

Problem: .git/hooks/ is local-only and not shared with the team. Use a framework instead.

Husky + lint-staged (Node.js Projects)

The modern standard for JavaScript/TypeScript projects. Husky manages Git hooks; lint-staged runs commands only on staged files for speed.

Quick Setup (Husky v9+)

# Install
npm install --save-dev husky lint-staged

# Initialize Husky (creates .husky/ directory)
npx husky init

# The init command creates a pre-commit hook β€” edit it:
echo "npx lint-staged" > .husky/pre-commit

Configure lint-staged in package.json

{
  "lint-staged": {
    "*.{js,jsx,ts,tsx}": [
      "eslint --fix --max-warnings=0",
      "prettier --write"
    ],
    "*.{css,scss}": [
      "prettier --write",
      "stylelint --fix"
    ],
    "*.{json,md,yml,yaml}": [
      "prettier --write"
    ]
  }
}

Add Commit Message Linting

# Install commitlint
npm install --save-dev @commitlint/cli @commitlint/config-conventional

# Create commitlint config
cat > commitlint.config.js << 'EOF'
module.exports = {
  extends: ['@commitlint/config-conventional'],
  rules: {
    'type-enum': [2, 'always', [
      'feat', 'fix', 'docs', 'style', 'refactor',
      'perf', 'test', 'build', 'ci', 'chore', 'revert'
    ]],
    'subject-max-length': [2, 'always', 72],
    'body-max-line-length': [2, 'always', 100]
  }
};
EOF

# Add commit-msg hook
echo "npx --no -- commitlint --edit \$1" > .husky/commit-msg

Add Pre-Push Hook

# Run tests before pushing
echo "npm test" > .husky/pre-push

Complete Husky Directory Structure

project/
β”œβ”€β”€ .husky/
β”‚   β”œβ”€β”€ pre-commit        # npx lint-staged
β”‚   β”œβ”€β”€ commit-msg        # npx --no -- commitlint --edit $1
β”‚   └── pre-push          # npm test
β”œβ”€β”€ commitlint.config.js
β”œβ”€β”€ package.json          # lint-staged config here
└── ...

pre-commit Framework (Python / Polyglot)

Language-agnostic framework that works with any project. Hooks are defined in YAML and run in isolated environments.

Setup

# Install (Python required)
pip install pre-commit

# Create config
cat > .pre-commit-config.yaml << 'EOF'
repos:
  # Built-in checks
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.6.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml

…
Pertanyaan umum

Apa itu 'git hooks'?

Git hooks adalah script yang berjalan otomatis pada titik tertentu dalam alur kerja Git, misalnya sebelum commit atau push.

Mengapa menggunakan alat seperti Husky?

Karena git hooks bawaan bersifat lokal di komputer Anda. Alat seperti Husky membantu membagikan konfigurasi ini ke seluruh anggota tim.

Apa fungsi 'lint-staged'?

Alat ini hanya menjalankan perintah pada file yang sudah Anda ubah dan masukkan ke staging untuk commit, sehingga prosesnya lebih cepat.

Detail

Deskripsi asli dari pembuat

Master Git hooks setup with Husky, lint-staged, pre-commit framework, and commitlint. Automate code quality gates, formatting, linting, and commit message enforcement before code reaches CI.

repo: sickn33/agentic-awesome-skills

Popularitas

Bintang GitHub
48k
Peringkat
#4735
Lisensi
MIT
Diperbarui
15/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa