Your First Config¶
GitHooks uses a single PHP file (githooks.php) to configure all QA tools, hooks, and execution options.
Generate the configuration¶
In interactive mode, conf:init:
- Detects QA tools already installed in
vendor/bin/(phpstan, phpcs, phpmd, etc.). - Asks which tools to include.
- Asks for source directories (comma-separated, default
src). - Asks which hook events to configure (
pre-commit,pre-push, both, or none). - Generates a tailored
githooks.php.
Non-interactive mode
Use githooks conf:init -n to copy a template file with examples of all supported job types. Useful for CI environments or if you prefer editing manually.
Anatomy of the configuration¶
The generated file returns a PHP array with three sections:
<?php
return [
'hooks' => [ ... ], // Map git events to flows/jobs
'flows' => [ ... ], // Named groups of jobs with shared options
'jobs' => [ ... ], // Individual QA tasks
];
graph LR
A[Git Event<br/>pre-commit] --> B[Flow<br/>qa]
B --> C[Job<br/>phpcs_src]
B --> D[Job<br/>phpstan_src]
B --> E[Job<br/>phpmd_src]
- Hooks map git events (
pre-commit,pre-push, etc.) to flows and/or jobs. - Flows are named groups of jobs with shared options like
fail-fastandprocesses. - Jobs are individual QA tasks. Each declares a
type(e.g.phpstan,phpcs) and its configuration.
See the Configuration reference for the full keyword documentation.
File location¶
GitHooks searches for the configuration file in this order:
./githooks.php./qa/githooks.php
You can also specify a custom path with --config=path/to/githooks.php on any command.
Validate the configuration¶
This verifies the structure, checks that referenced executables and paths exist, and reports errors and warnings.