markwalet/laravel-git-state

A Laravel package that gives you information about the current git state.
115,400 8
Install
composer require markwalet/laravel-git-state
Latest Version:v1.11.2
PHP:^8.2
License:MIT
Last Updated:Jun 23, 2026
Links: GitHub  ·  Packagist
Maintainer: markwalet

Laravel Git State

Build Status Total Downloads Latest Stable Version License

A Laravel package that gives you information about the current git state.

Installation

You can install this package with composer:

composer require markwalet/laravel-git-state

The package supports PHP 8.2+ and Laravel 12+.

Laravel auto-loads service providers for you, so you don't have to register it. If you want to register the service provider manually, add the following line to your config/app.php file:

MarkWalet\GitState\GitStateServiceProvider::class

Usage

When you want to get information about the current git state, you can inject the MarkWalet\GitState\Drivers\GitDriver class in your methods:

<?php

use MarkWalet\GitState\Drivers\GitDriver;

class Controller {
    
    public function index(GitDriver $driver) {
        $branch = $driver->currentBranch();
        $commit = $driver->latestCommitHash();
        $timestamp = $driver->latestCommitTimestamp(); // Carbon instance
        $title = $driver->latestCommitTitle();
        $description = $driver->latestCommitDescription();
        
        return view('index', compact('branch', 'commit', 'timestamp', 'title', 'description'));
    }
}

When injecting a GitDriver like this, you will get an instance of the default driver you configured. If you want to have more control over the driver you are using, you can use the MarkWalet\GitState\GitManager:

<?php

use MarkWalet\GitState\GitStateManager;

class Controller {
    
    public function index(GitStateManager $driver) {
        $branch = $driver->driver('other-driver')->currentBranch();
        
        return view('index', compact('branch'));
    }
}

Configuration

The default configuration is defined in git-state.php. If you want to edit this file you can copy it to your config folder by using the following command:

php artisan vendor:publish --provider="MarkWalet\GitState\GitServiceProvider"

In this file you can configure different drivers for fetching the current Git state, as well as setting a default configuration.

The supported drivers are: exec and file. There is also a fake implementation for testing purposes.

Related Packages

doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

637,827,751 9,703
laravel/framework

The Laravel Framework.

589,172,971 34,950
laravel/tinker

Powerful REPL for the Laravel framework.

498,216,183 7,442
laravel/serializable-closure

Laravel Serializable Closure provides an easy and secure way to serialize closur...

413,412,504 609
nunomaduro/collision

Cli error handling for console/command-line PHP applications.

394,964,158 4,660

Version History

Version Released PHP Laravel License
v1.11.2 ^8.2 ^12.0|^13.0 MIT
v1.11.1 ^8.2 ^12.0|^13.0 MIT
v1.11.0 ^8.2 ^12.0|^13.0 MIT
v1.10.0 ^8.1 ^10.0|^11.44.2|^12.0|^13.0 MIT
v1.9.2 ^8.1 ^10.0|^11.0|^12.0 MIT