Zum Inhalt springen

Git Hooks and Husky: Automatically Enforcing Code Quality

Veröffentlicht am Oct 28, 2025 | ca. 2 Min. Lesezeit |

Git hooks are executable scripts in .git/hooks/ that run automatically at specific Git events. The most important for code quality: pre-commit (runs before a commit is created) and pre-push (runs before pushing).

The problem with native hooks: .git/hooks/ isn't committed to the repository, so every developer must install hooks manually.

Husky solves this by storing hooks in .husky/ (committed to the repo) and auto-installing them via an npm prepare script.

lint-staged runs linters only on staged files (not the entire project), making hooks fast even in large codebases.

Recommended setup for Symfony projects:

  1. pre-commit: lint-staged with PHP CS Fixer (PSR-12), ESLint, Stylelint
  2. commit-msg: commitlint with Conventional Commits config
  3. pre-push: PHPUnit test suite
  4. post-merge: Auto-run composer install / npm install when lockfiles change

CI/CD pipelines serve as the final safety net — hooks can be bypassed with --no-verify, but pipelines cannot.

Thomas Wunner

Thomas Wunner

Certified IT specialist for application development with an instructor qualification and over 14 years of experience building scalable web applications with Symfony and Shopware. When not coding, Thomas volunteers as a lifeguard with the Wasserwacht, performs as a DJ, and explores the countryside on his motorbike.

Kommentare

Kommentare werden von Remark42 bereitgestellt. Beim Laden werden Daten an unseren Kommentar-Server übertragen.