brainmaestro/composer-git-hooks
Manage Git hooks via Composer for PHP projects. Install and run hooks automatically on composer install/update, keeping teams consistent without manual setup. Supports custom hook scripts and easy configuration for pre-commit, pre-push, and more.
Start by installing the package via Composer:
composer require --dev brainmaestro/composer-git-hooks
Then, add a extra.git-hooks section to your composer.json to define your hooks. For example:
{
"extra": {
"git-hooks": {
"pre-commit": [
"vendor/bin/phpstan analyse src",
"vendor/bin/php-cs-fixer fix --diff --ansi"
],
"pre-push": [
"composer test"
]
}
}
}
Run composer install (or update) — the hooks will be automatically installed into .git/hooks/. No manual setup required. First use case: ensure all developers run static analysis and linting before committing.
composer.json and share them across the team. Ideal for enforcing formatting (e.g., PHP-CS-Fixer, ESLint), security checks (e.g., composer audit), or tests (e.g., PHPUnit).if statements inside hook scripts for granular control (e.g., only lint changed files via git diff --cached --name-only).scripts/lint.sh) and reference them in composer.json for readability and reuse..git/hooks/* scripts are executable, or add chmod +x as a post-install script if needed.["a", "b"]) run sequentially and fail fast—first command exit non-zero stops the rest. Use && to chain inside one string if you want group logic.extra.git-hooks, re-run composer install (or update) to refresh the hooks. Consider adding "@git-hooks" to scripts.post-install-cmd and post-update-cmd to ensure hooks stay synced..git/hooks/ scripts are not overwritten—only missing or broken hooks are replaced. Use --force to override (avoid in CI).CONTRIBUTING.md or README that composer install is required to install hooks. Consider a pre-check in CI for missing hooks (e.g., GitHub Actions check: test -f .git/hooks/pre-commit).How can I help you explore Laravel packages today?