sebastian / git-state
Library for describing the state of a Git checkout
1.1.0
2026-10-21 05:59 UTC
Requires
- php: >=8.4
Requires (Dev)
- phpunit/phpunit: ^13.4.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-21 06:01:56 UTC
README
sebastian/git-state
Library for describing the state of a Git checkout.
Installation
You can add this library as a local, per-project dependency to your project using Composer:
composer require sebastian/git-state
If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
composer require --dev sebastian/git-state
Usage
test.php
use SebastianBergmann\GitState\Builder; $builder = new Builder; $state = $builder->build(); if ($state === false) { // Not a Git repository or no origin remote configured exit(1); } print $state->originUrl() . PHP_EOL; print $state->branch() . PHP_EOL; print $state->commit() . PHP_EOL; if ($state->isClean()) { print 'Working directory is clean' . PHP_EOL; } else { print $state->status() . PHP_EOL; }
github.com:sebastianbergmann/git-state.git
main
ab00820c3757dbd30a8caa185aa4515b98713238
M README.md
?? test.php
When only the commit that is checked out is needed, commit() returns its hash without requiring an origin remote:
commit.php
use SebastianBergmann\GitState\Builder; $commit = (new Builder)->commit(); if ($commit === false) { // Not a Git repository, no commit yet, or Git cannot be run exit(1); } print $commit . PHP_EOL;
ab00820c3757dbd30a8caa185aa4515b98713238