Composer Git Hooks


June 11th, 2019

Composer Git Hooks

You can easily manage git hooks in your composer configuration file with the Composer Git Hooks package by Ezinwa Okpoechi:

Manage git hooks easily in your composer configuration. This command line tool makes it easy to implement a consistent project-wide usage of git hooks. Specifying hooks in the composer file makes them available for every member of the project team. This provides a consistent environment and behavior for everyone which is great. It is also possible to use to manage git hooks globally for every repository on your computer. That way you have a reliable set of hooks crafted by yourself for every project you choose to work on.

By using the composer configuration file everyone that checks out the project will have the same behavior instead of each developer having to set up hooks individually.

Here’s an example of how you can configure git hooks in the composer extra configuration:

"extra": {
"hooks": {
"pre-commit": [
"echo committing as $(git config",
"php-cs-fixer fix ." // fix style
// verify commit message. ex: ABC-123: Fix everything
"commit-msg": "grep -q '[A-Z]+-[0-9]+.*' $1",
"pre-push": [
"php-cs-fixer fix --dry-run .", // check style
"post-merge": "composer update"

If you follow along in the project’s readme, you can add the following events to run cghooks every time the following events happen:

"scripts": {
"post-install-cmd": "cghooks add --ignore-lock",
"post-update-cmd": "cghooks update"

To learn more about this package, including source code, documentation, and examples, check out the project on GitHub at BrainMaestro/composer-git-hooks.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.