PHPackages                             indy2kro/laravel-git-hooks - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. indy2kro/laravel-git-hooks

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

indy2kro/laravel-git-hooks
==========================

🪝• Efficiently manage Git hooks in Laravel projects. Enhance code quality, save time on reviews, and prevent bugs from entering your repository.

2.2.0(8mo ago)02.5k—9.1%1[1 PRs](https://github.com/indy2kro/laravel-git-hooks/pulls)MITPHPPHP ^8.2CI passing

Since Apr 17Pushed 1mo agoCompare

[ Source](https://github.com/indy2kro/laravel-git-hooks)[ Packagist](https://packagist.org/packages/indy2kro/laravel-git-hooks)[ Docs](https://github.com/indy2kro/laravel-git-hooks)[ RSS](/packages/indy2kro-laravel-git-hooks/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (17)Versions (51)Used By (0)

🪝 Laravel Git Hooks
===================

[](#-laravel-git-hooks)

A powerful and easy-to-use package for managing Git hooks within your Laravel projects. Improve your code quality, reduce the time spent on code reviews, and catch potential bugs before they make it into your repository.

 [ ![Latest Version on Packagist](https://camo.githubusercontent.com/bbd0a732554d9777101f6b296f6e6646072416c7aa56125c2e60bcf353a65092/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f69676f7273676d2f6c61726176656c2d6769742d686f6f6b732e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/igorsgm/laravel-git-hooks) [ ![Build Status](https://camo.githubusercontent.com/fcd45107051f4f7a96cea7ebcb2bfdceee565ab94e172d1c0d7707b79f6d4774/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f69676f7273676d2f6c61726176656c2d6769742d686f6f6b732f6d61696e2e796d6c3f7374796c653d666c61742d737175617265) ](https://github.com/igorsgm/laravel-git-hooks/actions/workflows/main.yml/badge.svg) [![Test Coverage](https://camo.githubusercontent.com/4733dacf75b9afcf71f8c0e13d2031189a93c86584b769bc6f43ea1fc621b0a6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f69676f7273676d2f6c61726176656c2d6769742d686f6f6b732f6d61737465723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/4733dacf75b9afcf71f8c0e13d2031189a93c86584b769bc6f43ea1fc621b0a6/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f69676f7273676d2f6c61726176656c2d6769742d686f6f6b732f6d61737465723f7374796c653d666c61742d737175617265) [![Code Quality](https://camo.githubusercontent.com/73628666d1dc284eeaa41b818eb5880756c0eb72b960af8a913bdedf54c80ed2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f69676f7273676d2f6c61726176656c2d6769742d686f6f6b732f6d61737465723f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/73628666d1dc284eeaa41b818eb5880756c0eb72b960af8a913bdedf54c80ed2/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f7175616c6974792f672f69676f7273676d2f6c61726176656c2d6769742d686f6f6b732f6d61737465723f7374796c653d666c61742d737175617265) [ ![Total Downloads](https://camo.githubusercontent.com/ee26bf53338e7b1579eee39b17a56e0ebb1076aedc706c9e2331d673156934e1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f69676f7273676d2f6c61726176656c2d6769742d686f6f6b732e7376673f7374796c653d666c61742d737175617265) ](https://packagist.org/packages/igorsgm/laravel-git-hooks)

---

 [![Laravel Git Hooks usage sample](https://user-images.githubusercontent.com/14129843/234191523-859b962d-bfdf-4df7-88da-9c80ddb93607.png)](https://user-images.githubusercontent.com/14129843/234191523-859b962d-bfdf-4df7-88da-9c80ddb93607.png)

✨ Features
----------

[](#-features)

- **Pre-configured Hooks:** Laravel Git Hooks comes with pre-configured pre-commit hooks for popular tools, such as Laravel Pint, PHPCS, ESLint, Prettier, Larastan, Enlightn, Rector, PHP Insights, and Blade Formatter, making it easy to enforce coding standards and style guidelines right away.
- **Manage Git Hooks:** Easily manage your Git hooks in your Laravel projects with a streamlined and organized approach.
- **Edit Commit Messages:** Gain control over your commit messages by customizing them to meet your project requirements and maintain a clean Git history.
- **Create Custom Hooks:** Add and integrate custom hooks tailored to your specific project needs, ensuring better code quality and adherence to guidelines.
- **Artisan Command for Hook Generation:** The package includes a convenient Artisan command that allows you to effortlessly generate new hooks of various types, such as: `pre-commit`, `prepare-commit-msg`, `commit-msg`, `post-commit`, and `pre-push`.
- **Code Quality:** The package is thoroughly tested with &gt;95% code coverage, ensuring its reliability and stability in a wide range of Laravel projects.
- **Docker support:** Each hook can be configured to either run locally or inside a Docker container, with full Laravel Sail integration.
- **Auto-fix Capabilities:** Automatically fix code issues without manual intervention, with configurable re-run after fixes.

1️⃣ Installation
----------------

[](#1️⃣-installation)

**Laravel Version Support:** This package supports Laravel 11 and Laravel 12. Laravel 10 support has been deprecated.

- You can install the package via composer:

```
composer require igorsgm/laravel-git-hooks --dev
```

- Publish the config file and customize it as needed:

```
php artisan vendor:publish --tag=laravel-git-hooks
```

- Now, whenever you make a change to your `config/git-hooks.php` file, register your Git hooks by running the Artisan command:

```
php artisan git-hooks:register
```

Once you've configured and registered the hooks, you're all set!

2️⃣ General Usage
-----------------

[](#2️⃣-general-usage)

### Usage of the configured Pre-commit Hooks

[](#usage-of-the-configured-pre-commit-hooks)

To use the pre-configured pre-commit hooks provided by this package, simply edit the `pre-commit` section of the `git-hooks.php` config file. Here's an example of how to configure them:

```
'pre-commit' => [
    \Igorsgm\GitHooks\Console\Commands\Hooks\PintPreCommitHook::class, // Laravel Pint
    \Igorsgm\GitHooks\Console\Commands\Hooks\PHPCodeSnifferPreCommitHook::class, // PHPCS (with PHPCBF autofixer)
    \Igorsgm\GitHooks\Console\Commands\Hooks\PHPCSFixerPreCommitHook::class, // PHP CS Fixer
    \Igorsgm\GitHooks\Console\Commands\Hooks\LarastanPreCommitHook::class, // Larastan
    // \Igorsgm\GitHooks\Console\Commands\Hooks\EnlightnPreCommitHook::class, // Enlightn
    \Igorsgm\GitHooks\Console\Commands\Hooks\ESLintPreCommitHook::class, // ESLint
    \Igorsgm\GitHooks\Console\Commands\Hooks\PrettierPreCommitHook::class, // Prettier
    \Igorsgm\GitHooks\Console\Commands\Hooks\PhpInsightsPreCommitHook::class, // PhpInsights
    \Igorsgm\GitHooks\Console\Commands\Hooks\RectorPreCommitHook::class, // Rector
],
```

### 🔧 Auto-fix Capabilities

[](#-auto-fix-capabilities)

By default, the pre-commit hooks will stop at the first failure and will not continue with the remaining tools. If the tool contains a fixer option, it will prompt in the CLI to run the fix command.

The package includes powerful auto-fix functionality that can automatically resolve code style and formatting issues:

- **Interactive Fixing:** By default, when an issue is detected, you'll be prompted to run the fix command
- **Automatic Fixing:** Enable `automatically_fix_errors` to fix issues without prompts
- **Smart Re-running:** Enable `rerun_analyzer_after_autofix` to automatically verify fixes succeeded

This behavior can be adjusted using the following parameters from the `git-hooks.php` config file:

```
    // config/git-hooks.php
return [
    ...
    'automatically_fix_errors' => false,
    'rerun_analyzer_after_autofix' => false,
    'stop_at_first_analyzer_failure' => true,
];
```

3️⃣ Advanced Usage
------------------

[](#3️⃣-advanced-usage)

### 🐳 Laravel Sail Support

[](#-laravel-sail-support)

If you are using Laravel Sail and local PHP is not installed, you can adjust the following parameters in the `git-hooks.php` config file. This will force the local git hooks to use the `sail` command to execute the hooks:

```
    // config/git-hooks.php
    'use_sail' => env('GITHOOKS_USE_SAIL', false),
```

### 🐳 Docker Support

[](#-docker-support)

By default, commands are executed locally; however, this behavior can be adjusted for each hook using the parameters `run_in_docker` and `docker_container`:

```
    // config/git-hooks.php
    'run_in_docker' => env('LARAVEL_PINT_RUN_IN_DOCKER', true),
    'docker_container' => env('LARAVEL_PINT_DOCKER_CONTAINER', 'app'),
```

### 🔧🪲 Advanced Configuration Options &amp; Debug Mode

[](#-advanced-configuration-options--debug-mode)

The `git-hooks.php` config file offers several debug options that can be adjusted using the following parameters. It also provides additional configuration options for fine-tuning hook behavior:

```
    // config/git-hooks.php
return [
    ...
    'artisan_path' => base_path('artisan'),
    'validate_paths' => env('GITHOOKS_VALIDATE_PATHS', true),
    'analyzer_chunk_size' => env('GITHOOKS_ANALYZER_CHUNK_SIZE', 100),

    'output_errors' => env('GITHOOKS_OUTPUT_ERRORS', false),

    'debug_commands' => env('GITHOOKS_DEBUG_COMMANDS', false),
    'debug_output' => env('GITHOOKS_DEBUG_OUTPUT', false),
    ...
];
```

### 🛠️ Creating Custom Git Hooks

[](#️-creating-custom-git-hooks)

1. If you need to create a custom Git hook for your project, Laravel Git Hooks makes it easy with the `git-hooks:make` Artisan command. To create a new custom hook, simply run the following command: ```
    php artisan git-hooks:make
    ```

    This command will prompt you to choose the type of hook you want to create (e.g., `pre-commit`, `post-commit`, etc.) and to provide a name for the hook. Once you've provided the required information, the command will generate a new hook class in the `app/Console/GitHooks` directory.
2. To start using your custom hook, open the generated file and implement the `handle()` method with your desired logic.
3. Add your custom hook to the appropriate array in the `git-hooks.php` config file:

```
'pre-commit' => [
    // Other pre-commit hooks...
    \App\Console\GitHooks\MyCustomPreCommitHook::class,
],
```

4. Finally, register your custom hook by running the Artisan command:

```
php artisan git-hooks:register
```

4️⃣ Handling Git Hooks
----------------------

[](#4️⃣-handling-git-hooks)

### Pre-commit Hook

[](#pre-commit-hook)

> The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine whatever you need to inspect in the code. Exiting non-zero from this hook aborts the commit, although you can bypass it with git commit --no-verify. You can do things like check for code style (run lint or something equivalent), check for trailing whitespace (the default hook does exactly this), or check for appropriate documentation on new methods.

```
// config/git-hooks.php
return [
    ...
    'pre-commit' => [
        \App\Console\GitHooks\MyPreCommitHook::class,
    ],
    ...
];
```

```
// App/Console/GitHooks/MyPreCommitHook.php

namespace App\Console\GitHooks;

use Closure;
use Igorsgm\GitHooks\Git\ChangedFiles;

class MyPreCommitHook implements \Igorsgm\GitHooks\Contracts\PreCommitHook
{
    // ...

    public function handle(ChangedFiles $files, Closure $next)
    {
        // TODO: Implement your pre commit hook logic here.

        // If you want to cancel the commit, you have to throw an exception.
        // i.e: throw new HookFailException();

        // Run the next hook in the chain
        return $next($files);
    }
}
```

### Prepare-commit-message Hook

[](#prepare-commit-message-hook)

> The prepare-commit-msg hook is run before the commit message editor is fired up but after the default message is created. It lets you edit the default message before the commit author sees it. This hook takes a few parameters: the path to the file that holds the commit message so far, the type of commit, and the commit SHA-1 if this is an amended commit. This hook generally isn't useful for normal commits; rather, it's good for commits where the default message is auto-generated, such as templated commit messages, merge commits, squashed commits, and amended commits. You may use it in conjunction with a commit template to programmatically insert information.

```
// config/git-hooks.php
return [
    ...
    'prepare-commit-msg' => [
        \App\Console\GitHooks\MyPrepareCommitMessageHook::class,
    ],
    ...
];
```

```
// App/Console/GitHooks/MyPrepareCommitMessageHook.php

namespace App\Console\GitHooks;

use Closure;
use Igorsgm\GitHooks\Git\CommitMessage;
use Igorsgm\GitHooks\Contracts\MessageHook;

class MyPrepareCommitMessageHook implements \Igorsgm\GitHooks\Contracts\MessageHook
{
    // ...

    public function handle(CommitMessage $message, Closure $next)
    {
        // TODO: Implement your prepare commit msg hook logic here.

        $currentMessage = $message->getMessage();
        // You can update commit message text
        $message->setMessage(str_replace('issue', 'fixed', $currentMessage));

        // If you want to cancel the commit, you have to throw an exception.
        // i.e: throw new HookFailException();

        // Run the next hook in the chain
        return $next($message);
    }
}
```

### Commit-msg Hook

[](#commit-msg-hook)

> The commit-msg hook takes one parameter, which is the path to a temporary file that contains the commit message written by the developer. If this script exits non-zero, Git aborts the commit process, so you can use it to validate the commit message format.

```
// config/git-hooks.php
return [
    ...
    'commit-msg' => [
        \App\Console\GitHooks\MyCommitMessageHook::class,
    ],
    ...
];
```

The class structure of the `commit-msg` hook is the same as the `prepare-commit-msg` hook, shown right above.

### Post-commit Hook

[](#post-commit-hook)

> After the entire commit process is completed, the post-commit hook runs. It doesn't take any parameters, but you can easily get the last commit by running git log -1 HEAD. Generally, this script is used for notification or something similar.

```
// config/git-hooks.php
return [
    ...
    'post-commit' => [
        \App\Console\GitHooks\MyPostCommitHook::class,
    ],
    ...
];
```

```
// App/Console/GitHooks/MyPostCommitHook.php

namespace App\Console\GitHooks;

use Closure;
use Igorsgm\GitHooks\Git\Log;
use Igorsgm\GitHooks\Contracts\PostCommitHook;

class MyPostCommitHook implements \Igorsgm\GitHooks\Contracts\PostCommitHook
{
    // ...

    public function handle(Log $log, Closure $next)
    {
        // TODO: Implement post commit hook logic here.

        // You can interact with the commit log
        $hash = $log->getHash();
        $author = $log->getAuthor();
        $date = $log->getDate();
        $message = $log->getMessage();

        // If you want to cancel the commit, you have to throw an exception.
        // i.e: throw new HookFailException();

        // Run the next hook in the chain
        return $next($log);
    }
}
```

### Pre-push Hook

[](#pre-push-hook)

> The pre-push hook runs during git push, after the remote refs have been updated but before any objects have been transferred. It receives the name and location of the remote as parameters, and a list of to-be-updated refs through stdin. You can use it to validate a set of ref updates before a push occurs (a non-zero exit code will abort the push).

```
// config/git-hooks.php
return [
    ...
    'pre-push' => [
        \App\Console\GitHooks\MyPrePushHook::class,
    ],
    ...
];
```

The class structure of the `pre-push` hooks is the same as the `post-commit` hook shown above, but implementing `\Igorsgm\GitHooks\Contracts\PrePushHook` interface.

🧪 Testing
---------

[](#-testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Original Authors
----------------

[](#original-authors)

- [Igor Moraes](https://github.com/igorsgm)
- [Pavel Buchnev](https://github.com/butschster)

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Credits

[](#credits)

- [Cristian Radu](https://github.com/indy2kro)

License
-------

[](#license)

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

###  Health Score

48

—

FairBetter than 94% of packages

Maintenance77

Regular maintenance activity

Popularity22

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 78.1% 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 ~48 days

Recently: every ~43 days

Total

11

Last Release

265d ago

PHP version history (2 changes)v2.0.0PHP ^8.1

2.2.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1812715?v=4)[Cristi Radu](/maintainers/indy2kro)[@indy2kro](https://github.com/indy2kro)

---

Top Contributors

[![igorsgm](https://avatars.githubusercontent.com/u/14129843?v=4)](https://github.com/igorsgm "igorsgm (132 commits)")[![snyk-bot](https://avatars.githubusercontent.com/u/19733683?v=4)](https://github.com/snyk-bot "snyk-bot (21 commits)")[![indy2kro](https://avatars.githubusercontent.com/u/1812715?v=4)](https://github.com/indy2kro "indy2kro (7 commits)")[![dsbilling](https://avatars.githubusercontent.com/u/9788214?v=4)](https://github.com/dsbilling "dsbilling (3 commits)")[![benlumley](https://avatars.githubusercontent.com/u/194052?v=4)](https://github.com/benlumley "benlumley (3 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![algorhythm](https://avatars.githubusercontent.com/u/427134?v=4)](https://github.com/algorhythm "algorhythm (1 commits)")

---

Tags

gitpre-commitpre-commit-hookgit-hookslaravel-git-hookspint-pre-commit

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/indy2kro-laravel-git-hooks/health.svg)

```
[![Health](https://phpackages.com/badges/indy2kro-laravel-git-hooks/health.svg)](https://phpackages.com/packages/indy2kro-laravel-git-hooks)
```

###  Alternatives

[igorsgm/laravel-git-hooks

🪝• Efficiently manage Git hooks in Laravel projects. Enhance code quality, save time on reviews, and prevent bugs from entering your repository.

2931.7k1](/packages/igorsgm-laravel-git-hooks)[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[psalm/plugin-laravel

Psalm plugin for Laravel

3274.9M308](/packages/psalm-plugin-laravel)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[illuminate/queue

The Illuminate Queue package.

20331.4M1.2k](/packages/illuminate-queue)

PHPackages © 2026

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