Git Hooks: Automation in the Development Workflow
Last updated: March 2026 · Reading time: 6 minutes
Code reviews and CI/CD pipelines catch errors — but late in the process. Git Hooks act earlier: directly on the developer's machine, before the code reaches the repository.
What Git Hooks Are
Git Hooks are shell scripts in the .git/hooks/ directory of a repository. Git executes them during specific events. The most important:
pre-commit. Runs before every commit. Checks coding standards, syntax errors and formats code automatically. If the script fails, the commit is aborted.
commit-msg. Checks the commit message. Enforces naming conventions like "PROJ-123: description" for traceability.
pre-push. Runs before a push. Starts unit tests or linting — the push is aborted if tests fail.
post-merge. Runs after a merge. Automatically executes "composer install" or "drush updatedb" so the local environment stays up to date.
Git Hooks for Drupal Projects
PHP CodeSniffer. In the pre-commit hook, PHPCS checks code against Drupal coding standards. Incorrectly formatted code is not committed.
PHPStan. Static analysis finds type errors and undefined variables before code is executed.
YAML validation. Drupal configurations are stored as YAML files. A hook checks syntax and prevents faulty configurations.
Automatic formatting. Tools like PHP-CS-Fixer format code automatically in the pre-commit hook. No manual cleanup needed.
Sharing Hooks Across the Team
Git Hooks are local and not automatically shared. Tools like Husky, GrumPHP or Captain Hook solve this: the hook configuration is versioned in the repository and automatically installed during "composer install". Every team member works with the same quality checks.
Optimize Your Development Workflow?
arocom sets up Git Hooks and CI/CD pipelines for Drupal projects. The Future Check evaluates your development process. Starting at EUR 2,500 plus VAT, credited toward the follow-up project.
Can Git Hooks be bypassed?
Yes, with the --no-verify option. This is intentionally possible for exceptional cases. The CI/CD pipeline then catches issues as a second line of defense. Git Hooks are the first, not the only quality assurance.
Do Git Hooks slow down the workflow?
Well-configured hooks run in seconds. The pre-commit hook should only check changed files, not the entire repository. Slow tests belong in the pre-push hook or the CI/CD pipeline.
Which tools does arocom recommend for Git Hooks?
GrumPHP for PHP projects and Drupal. It integrates PHPCS, PHPStan, YAML lint and other checkers in one configurable pre-commit hook. The configuration is distributed via Composer.
Read more
- Git in the Drupal Context — Version control explained
- DevOps — Automation in development
- Deployment — Delivering code safely
Discover a random article
Questions about this topic? We'd love to help.
CMS Comparison 2025
Drupal vs. WordPress vs. TYPO3: An objective comparison for enterprise projects.
Was this article helpful?