PHPackages                             wtyd/githooks - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. wtyd/githooks

ActiveLibrary[Testing &amp; Quality](/categories/testing)

wtyd/githooks
=============

Manage git hooks in a simple and sophisticated way.

v2.7.0(11mo ago)922.7k↓26.7%MITPHPPHP &gt;=7.1CI passing

Since Dec 3Pushed 1mo ago4 watchersCompare

[ Source](https://github.com/Wtyd/githooks)[ Packagist](https://packagist.org/packages/wtyd/githooks)[ RSS](/packages/wtyd-githooks/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (13)Versions (25)Used By (0)

 [![](https://camo.githubusercontent.com/8af2f7fb7b2cdb28bcea2f1cfd78a3da13321f682b601845fcd5e6c4d515813d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6173742d636f6d6d69742f577479642f676974686f6f6b73)](https://github.com/Wtyd/githooks/commits/ "Last Commit") [![](https://camo.githubusercontent.com/ec8dd31c7da65619d45b30067fcedd52d8691fceb39b161e3aa42a05c8913b1a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f577479642f676974686f6f6b73)](https://github.com/Wtyd/githooks/issues "Open Issues") [![](https://camo.githubusercontent.com/4130f2665fd07850b5463dd68af466ab4cfba84d3cb5cfa3ed4eea3b17ef7649/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f577479642f676974686f6f6b73)](https://github.com/Wtyd/githooks/blob/master/LICENSE "License") [![PHP Versions Supported](https://camo.githubusercontent.com/72af429f1cc4b8fd73678e90ae9bf1a1f67e7b4267411d70ba4f436114ab2686/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e31253230746f253230382e342d3737376262332e7376673f6c6f676f3d706870266c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d353535353535)](#2-requirements "PHP Versions Supported") [![](https://camo.githubusercontent.com/66b29284c4e11f77c5ebedce6e311fa277408ccf195536fb8849654062b0369e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f577479642f676974686f6f6b73)](https://camo.githubusercontent.com/66b29284c4e11f77c5ebedce6e311fa277408ccf195536fb8849654062b0369e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f762f72656c656173652f577479642f676974686f6f6b73)

 [![](https://github.com/Wtyd/githooks/workflows/Code Analysis/badge.svg)](https://github.com/Wtyd/githooks/actions?query=workflow%3A%22Code Analysis%22 "Build") [![](https://github.com/Wtyd/githooks/workflows/Main Tests/badge.svg)](https://github.com/Wtyd/githooks/actions?query=workflow%3A%22Main Tests%22 "Build") [![](https://github.com/Wtyd/githooks/workflows/Schedule CI/badge.svg)](https://github.com/Wtyd/githooks/actions?query=workflow%3A%22Schedule CI%22 "Build")

1. Wtyd/GitHooks
================

[](#1-wtydgithooks)

Are many other tools and composer plugins for manage git hooks. But GitHooks offers:

- Standalone app. GitHooks is a binary ([.phar](https://www.php.net/phar)) so its dependencies don't interfere with your application's dependencies.
- Is managed with Composer. You don't need other tools like Phive or others.
- Crentralizes all QA tools configuration (all of supported tools at least).
- It abstracts developers away from how QA tools have to be executed by using only the `githooks tool name-of-the-tool` command.
- You can also create your own scripts and configure any git hook.

Further, it can be used together with javascript validation tools like [typicode/husky](https://github.com/typicode/husky) if you have hybrid projects.

2. Requirements
===============

[](#2-requirements)

- PHP &gt;= 7.1
- The tools you need to check the code.
- Or your owns scripts for the hooks.

3. Install
==========

[](#3-install)

#### 1. GitHooks must be installed like dev requirement with composer:

[](#1-githooks-must-be-installed-like-dev-requirement-with-composer)

```
composer require --dev wtyd/githooks
```

**Note:** for php &lt; 8.1 you must add the next `post-update-cmd` event to the `scripts` section in your `composer.json`:

```
"scripts": {
    "post-update-cmd": [
      "Wtyd\\GitHooks\\Utils\\ComposerUpdater::phpOldVersions"
    ]
}
```

Then run `composer update wtyd/githooks`.

> Until version 2.3.0 the method used was **php72orMinorUpdate** but it has been deprecated and will be removed from version 3.0.0

It is also convenient to add it to the `post-install-cm` event so that the rest of the project developers do not have problems with the build

```
"scripts": {
    "post-update-cmd": "Wtyd\\GitHooks\\Utils\\ComposerUpdater::phpOldVersions",
    "post-install-cmd": "Wtyd\\GitHooks\\Utils\\ComposerUpdater::phpOldVersions"
}
```

#### 2. Install all needed [supported tools](#5-supported-tools). How you install the tools doesn't matter.

[](#2-install-all-needed-supported-tools-how-you-install-the-tools-doesnt-matter)

#### 3. Initialize GitHooks with `githooks conf:init`. This command creates the configuration file in the root path (`githooks.php`).

[](#3-initialize-githooks-with-githooks-confinit-this-command-creates-the-configuration-file-in-the-root-path-githooksphp)

#### 4. Run `githooks hook`. It Copies the script for launch GitHooks on the pre-commit event in `.git/hooks` directory. You can, also run `githooks hook otherHook MyScriptFile.php` for set any hook with a custom script. See the [wiki](https://github.com/Wtyd/githooks/wiki/Console%20Commands#hook) for more information.

[](#4-run-githooks-hook-it-copies-the-script-for-launch-githooks-on-the-pre-commit-event-in-githooks-directory-you-can-also-run-githooks-hook-otherhook-myscriptfilephp-for-set-any-hook-with-a-custom-script-see-the-wiki-for-more-information)

To ensure that it is configured automatically, we can configure the command in the `post-update-cmd` and `post-install-cmd` events of the `composer.json` file (`scripts` section):

```
"scripts": {
    "post-update-cmd": [
    "vendor/bin/githooks hook" // or "vendor/bin/githooks hook pre-commit MyScriptFile.php"
    ],
    "post-install-cmd": [
    "vendor/bin/githooks hook"
    ]
}
```

#### 5. [Set the configuration file](#6-set-the-configuration-file).

[](#5-set-the-configuration-file)

4. Usage
========

[](#4-usage)

When you commit, all the configured code check tools are automatically launched. If your code pass all checks, GitHooks allows you to commit. If not, you have to fix the code and try again.

**All checks passed:**

```
✔️ parallel-lint - OK. Time: 150ms
✔️ phpcs - OK. Time: 890ms
✔️ phpstan - OK. Time: 2.34s
✔️ phpmd - OK. Time: 1.23s

Total Runtime: 3.45s

Results: 4/4 passed ✔️

```

**Some checks failed:**

```
✔️ parallel-lint - OK. Time: 150ms
✔️ phpcs - OK. Time: 890ms
❌ phpstan - KO. Time: 2.34s
  ┌───────────────────────────────────────────────────────────────────────────────
  │ /src/Foo.php:12  Access to undefined property $bar
  │ /src/Foo.php:34  Method doSomething() has no return type
  └───────────────────────────────────────────────────────────────────────────────
✔️ phpmd - OK. Time: 1.23s

Total Runtime: 3.45s

Results: 3/4 passed
  ❌ phpstan

```

You can also run GitHooks whenever you want. All tools at same time or one by one:

```
githooks tool all  # Run all tools
githooks tool phpcs  # Run only phpcs
```

5. Supported Tools
==================

[](#5-supported-tools)

At this moment, the supported tools are:

- [Php CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) (phpcs and phpcbf)
- [Php Copy Paste Detector](https://github.com/sebastianbergmann/phpcpd)
- [Php Mess Detector](https://phpmd.org/)
- [Parallel-lint](https://github.com/php-parallel-lint/PHP-Parallel-Lint)
- [Php Stan](https://github.com/phpstan/phpstan)
- [PHPUnit](https://phpunit.de/)
- [Psalm](https://psalm.dev/)
- **Script** — Generic tool type for running any QA tool not natively supported by GitHooks (e.g. php-cs-fixer, infection, pdepend). Only requires `executablePath`.
- [Local PHP Security Checker](https://github.com/fabpot/local-php-security-checker) Since Composer 2.4 local php security checker is replaced by `composer audit`

You can also set your [own script](https://github.com/Wtyd/githooks/wiki/Console%20Commands#set-your-own-script) on any git hook.

6. Set the Configuration File
=============================

[](#6-set-the-configuration-file)

The `githooks.yml` file is splitted on three parts:

6.1. Options
------------

[](#61-options)

### 6.1.1. Execution

[](#611-execution)

The `execution` flag marks how GitHooks will run:

- `full` (the default option): executes always all tools setted against all path setted for each tool. For example, you setted phpcs for run in `src` and `app` directories. The commit only contains modified files from `database` directory. Phpcs will check `src` and `app` directories even if no files in these directories have been modified.
- `fast`: this option runs the tools only against files modified by commit.
    - This option only affects the following tools: phpcs, phpcbf, phpmd, phpstan, psalm and parallel-lint. The rest of the tools will run as the full option.
    - **WARNING!!!** You must set the excludes of the tools either in `githooks.yml` or in the configuration file of each tool since this option overwrites the key `paths` of the tools so that they are executed only against the modified files.

#### Per-tool execution mode

[](#per-tool-execution-mode)

You can override the global execution mode for individual tools by adding an `execution` key to the tool's configuration:

```
'Options' => [
    'execution' => 'full', // Global default
],
'phpcs' => [
    'paths' => ['src'],
    // No execution key: inherits global 'full'
],
'phpcbf' => [
    'execution' => 'fast', // Override: only modified files
    'paths' => ['src'],
],
```

**Priority:** CLI argument &gt; per-tool setting &gt; global Options &gt; default (`full`).

When you pass execution from the CLI (e.g. `githooks tool all fast`), it overrides both global and per-tool settings for that run.

### 6.1.2. Processes

[](#612-processes)

Run multiple tools in multiple processes at same time (`tool all` command). The default number of processes is 1.

6.2. Tools
----------

[](#62-tools)

It is an array with the name of the tools that GitHooks will run. The name of the tools is their executable. If you want all the tools to be executed, the `Tools` key will be as follows:

```
'Tools' => [
        'security-checker',
        'phpstan',
        'parallel-lint',
        'phpcbf',
        'phpcs',
        'phpmd',
        'phpcpd',
        'phpunit',
        'psalm',
        'script',
],
```

The order in which the tools are is the order in which they will be executed.

6.3. Setting Tools
------------------

[](#63-setting-tools)

In next step you must configure the tools with the same name as in the *Tools* key. For example, for set phpcs:

```
'phpcs' => [
        'executablePath' => 'phpcs',
        'execution' => 'fast', // Optional: override global execution mode (full/fast)
        'paths' => ['./'],
        'standard' => './myRules.xml', // or predefined rules: Squiz, PSR12, Generic, PEAR
        'ignore' => ['vendor'],
],
```

The `script` tool type allows you to run any external tool not natively supported by GitHooks. Unlike other tools, `executablePath` is **required** (there is no default). You can set a custom `name` to use in the `Tools` array and CLI instead of `script`:

```
'script' => [
        'name' => 'php-cs-fixer', // Optional: use 'php-cs-fixer' in Tools array and CLI
        'executablePath' => 'vendor/bin/php-cs-fixer',
        'otherArguments' => 'fix --dry-run --config=.php-cs-fixer.php',
        'ignoreErrorsOnExit' => false,
],
```

With `name` set, use the custom name in the `Tools` array and run it with `githooks tool php-cs-fixer`.

All the available options are in the [wiki](https://github.com/Wtyd/githooks/wiki/ConfigurationFile).

7. Contributing
===============

[](#7-contributing)

Contributions from others would be very much appreciated! Send [pull request](https://github.com/Wtyd/githooks/pulls)/[issue](https://github.com/Wtyd/githooks/issues). Check all steps for do that at Wiki section for [Contributing](https://github.com/Wtyd/githooks/wiki/Contributing). Thanks!

8. License
==========

[](#8-license)

The MIT License (MIT). Please see [License File](/LICENSE) for more information.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance73

Regular maintenance activity

Popularity32

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~150 days

Recently: every ~269 days

Total

12

Last Release

333d ago

Major Versions

v1.0.1 → 2.0.02021-10-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/4d3092adf56f0dda66e5de0fba442ad0c6e5eeafa66712452c01997717340233?d=identicon)[Wtyd](/maintainers/Wtyd)

---

Top Contributors

[![Wtyd](https://avatars.githubusercontent.com/u/13366202?v=4)](https://github.com/Wtyd "Wtyd (293 commits)")[![Pablo-Lilao](https://avatars.githubusercontent.com/u/63185445?v=4)](https://github.com/Pablo-Lilao "Pablo-Lilao (8 commits)")[![TESTPERSONAL](https://avatars.githubusercontent.com/u/6664588?v=4)](https://github.com/TESTPERSONAL "TESTPERSONAL (1 commits)")

---

Tags

automationcheckercicoding-standardsgitgithookshookhooksphpphp-librarypre-commitprecommitprecommit-hooksqaqualitystatic-analysistestingcliconsoleqagithookscommitpre-commitgithooksprecommit

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/wtyd-githooks/health.svg)

```
[![Health](https://phpackages.com/badges/wtyd-githooks/health.svg)](https://phpackages.com/packages/wtyd-githooks)
```

###  Alternatives

[captainhook/captainhook

PHP git hook manager

1.1k6.8M370](/packages/captainhook-captainhook)[projektgopher/whisky

A simple CLI tool for managing a project's git hooks across multiple members.

241281.3k20](/packages/projektgopher-whisky)[acquia/orca

A tool for testing a company's software packages together in the context of a realistic, functioning, best practices Drupal build

32902.4k](/packages/acquia-orca)[guanguans/ai-commit

Automagically generate conventional git commit message with AI. - 使用 AI 自动生成约定式 git 提交信息。

39231.2k10](/packages/guanguans-ai-commit)[moxio/captainhook-eslint

Captain Hook Plugin to validate files using ESLint

1147.9k](/packages/moxio-captainhook-eslint)[bernardosilva/git-hooks-php

Composer git-hook package with hooks for your php projects.

2516.7k1](/packages/bernardosilva-git-hooks-php)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
