Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Composer Git Hooks

Composer Git Hooks Laravel Package

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.

Deep Wiki
Context7

brainmaestro/composer-git-hooks is a Composer plugin that lets you manage Git hooks (like pre-commit and pre-push) directly from your PHP project. It installs and updates hook scripts automatically via Composer, keeping development workflows consistent across teams and environments.

Define hooks in your composer.json, commit the hook scripts, and ensure everyone gets the same checks and automation without manual setup.

  • Configure multiple Git hooks from composer.json
  • Auto-install/update hooks on composer install / composer update
  • Store hook scripts in your repo for team-wide consistency
  • Works with common workflows (linting, tests, formatting, CI guards)
  • Simple setup with predictable, repeatable behavior
Frequently asked questions about Composer Git Hooks
How do I add Git hooks to my Laravel project using Composer?
Define hooks in your `composer.json` under the `extra.git-hooks` section, then run `composer install` or `composer update`. The plugin will automatically install and update the hooks in your `.git/hooks` directory. Example: Add a `pre-commit` hook by specifying the script path in the config.
Does this package support Laravel’s dependency management?
Yes, it integrates natively with Composer, so hooks are managed alongside other Laravel dependencies. This ensures hooks are installed consistently across all environments, including local dev, staging, and production, as long as Composer is used for dependency resolution.
Can I use this for pre-commit PHPStan or PHPUnit tests in Laravel?
Absolutely. You can configure the package to run PHPStan or PHPUnit as pre-commit hooks by defining the script paths in `composer.json`. The hooks execute before commits, blocking invalid code from being pushed. Example: `"pre-commit": ["vendor/bin/phpstan analyze", "vendor/bin/phpunit"]`.
Will this work with Laravel Forge or Envoyer for deployment?
Yes, since hooks are managed via Composer, they’ll be installed on any server where you run `composer install`. However, ensure your deployment scripts include Composer updates to avoid missing hooks. For Envoyer, add a `composer install` step in your deployment recipe.
How do I migrate existing manual Git hooks to this package?
Move your hook scripts (e.g., `pre-commit`, `pre-push`) into your project’s root or a designated `hooks/` directory, then reference them in `composer.json` under `extra.git-hooks`. Run `composer install` to replace manual hooks with the Composer-managed versions. Backup old hooks before migration.
Does this package support Laravel 10+ and PHP 8.1+?
Yes, the package is designed to work with modern Laravel versions (9.x and 10.x) and PHP 8.1+. It leverages Composer’s plugin system, which is fully compatible with these environments. Check the package’s Composer constraints for exact version requirements.
Can I customize hook behavior (e.g., exit codes, logging) in Laravel?
Yes, you can customize hook scripts directly in your project. The package only handles installation and updates; the scripts themselves can include Laravel-specific logic, like checking `.env` files or running Artisan commands. Example: Use `php artisan test` in a pre-push hook.
What if a hook fails in production? Will it block deployments?
Hooks run locally or on the server where Composer installs them. In production, failing hooks (e.g., pre-push) won’t block deployments unless explicitly configured to do so. For CI/CD pipelines, consider using the package’s hooks as guardrails in staging, not production.
Are there alternatives to this package for Laravel Git hooks?
Alternatives include `evilmartians/composer-hooks` or manual `.git/hooks` setup, but this package offers tighter Composer integration and Laravel-friendly features like Artisan command hooks. It’s ideal for teams wanting hooks managed alongside Laravel dependencies without extra tooling.
How do I test Git hooks locally before committing to Laravel projects?
Use `composer hooks:test` (if supported) or manually trigger hooks with `git commit --no-verify` to bypass them. For pre-push, simulate it with `GIT_PUSH=true git push --dry-run`. Ensure hooks are committed to your repo so all team members get the same behavior during testing.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport