Git hooks: run linting and tests before every commit

8 steps · about 2 h 25 min · Intermediate

  1. Git Hooks - A Guide for Programmers (reference, githooks.com, 10 min)

    A short overview of what hooks are and which events exist, so you have the map before you start.

  2. Git - Git Hooks (doc, Pro Git book, git-scm.com, 15 min)

    The official explanation of the commit-workflow hooks, including that a non-zero exit aborts the commit and --no-verify bypasses it.

  3. Beginner's guide to Git hooks - Graphite (guide, Graphite, 10 min)

    Separates client-side from server-side hooks and shows a first linter script.

  4. Git hooks: How to automate actions in your Git repo (tutorial, Red Hat, 15 min)

    Walks you through writing and running your first hand-made pre-commit script that inspects staged files.

  5. How to Set Up Pre-Commit Hooks (tutorial, Stefanie Molin, 25 min)

    Moves from hand-written scripts to the pre-commit framework, with a YAML config and ruff for Python.

  6. How to set up a pre-commit Git hook with Husky and lint-staged (tutorial, Olivia Coumans, 25 min)

    The JavaScript equivalent, and it explains how Husky works under the hood through core.hooksPath.

  7. lint-staged: Run tasks like formatters and linters against files staged in Git (repo, GitHub, lint-staged, 20 min)

    The official docs for running checks on staged files only, which keeps hooks fast.

  8. Git Hooks with Husky and lint-staged: The Complete Setup Guide for 2025 (tutorial, DEV Community, 25 min)

    Finishes with commit-msg checks, pre-push, and the trade-off of running slow tests in a hook or in CI.