PHPackages                             grimzy/git-info - 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. grimzy/git-info

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

grimzy/git-info
===============

Utility library to retrieve Git information from a working directory.

v1.0.0(6y ago)268[1 issues](https://github.com/grimzy/git-info/issues)MITPHPPHP &gt;=7.1CI failing

Since Mar 3Pushed 6y ago2 watchersCompare

[ Source](https://github.com/grimzy/git-info)[ Packagist](https://packagist.org/packages/grimzy/git-info)[ RSS](/packages/grimzy-git-info/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (3)Versions (9)Used By (0)

GitInfo
=======

[](#gitinfo)

[![Build Status](https://camo.githubusercontent.com/5724eac221c7846bcac5f3428effc5b6f7e31a5684b2b70a4f9c024874d9853a/68747470733a2f2f7472617669732d63692e6f72672f6772696d7a792f6769742d696e666f2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/grimzy/git-info) [![Maintainability](https://camo.githubusercontent.com/3772a61e6e836e11ced59b0d9cdbd956d72b2c4e067826fc6d00c42ce7496b84/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f61343730646463326439636563343063366232662f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/grimzy/git-info/maintainability) [![Test Coverage](https://camo.githubusercontent.com/5e1f4f56bd341721470de1a40602c886111231db89b79ecdf63356e3006f8220/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f61343730646463326439636563343063366232662f746573745f636f766572616765)](https://codeclimate.com/github/grimzy/git-info/test_coverage) [![StyleCI](https://camo.githubusercontent.com/c79b3151665285c91e4444b192350184965e48b35d301c4973a4c94108d359bb/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134353137383836342f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/145178864)

> Utility library to retrieve Git information from a working directory.

**Minimum requirement:** PHP 7.1

---

Installation
------------

[](#installation)

```
composer require git-info
```

Usage
-----

[](#usage)

```
// Instantiate GitInfo
$gitInfo = new \Grimzy\GitInfo\GitInfo();

// Run all registered commands
$info = $gitInfo->getInfo();

// $info = [
//     'commit-hash-long' => 'd93287e02a3b7823623f383ffb443d686b41e5ae',
//     'commit-hash-short' => 'd93287',
//     'author-name' => 'John Doe',
//     'author-email' => 'john.doe@git-info',
//     'author-date' => '2018-08-17T20:58:21-04:00',
//     'subject' => 'Release v1.2.3'
//     'branch' => 'master'
//     'version' => 'v1.2.3'
// ]

// Run a subset of commands
$info = $gitInfo->getInfo(['branch', 'commit-hash-short', 'author-date']);

// $info = [
//     'branch' => 'master'
//     'commit-hash-short' => 'd93287',
//     'author-date' => '2018-08-17T20:58:21-04:00'
// ]

// Run one command
$info = $gitInfo->getInfo('version');

// $info = 'v1.2.3'
```

Commands
--------

[](#commands)

### Get registered commands

[](#get-registered-commands)

```
$commands = GitInfo::getCommands();

// Default commands:
// $commands = [
//     'commit-hash-long'  => 'git log -1 --pretty=%H',
//     'commit-hash-short' => 'git log -1 --pretty=%h',
//     'author-name'       => 'git log -1 --pretty=%aN',
//     'author-email'      => 'git log -1 --pretty=%aE',
//     'author-date'       => 'git log -1 --pretty=%aI',
//     'subject'           => 'git log -1 --pretty=%s',
//     'branch'            => 'git rev-parse --abbrev-ref HEAD',
//     'version'           => 'git describe --always --tags --abbrev=0'
// ]
```

### Add commands to GitInfo

[](#add-commands-to-gitinfo)

**When instantiating:**

```
$gitInfo = new \Grimzy\GitInfo\GitInfo(null, [
    'status' => 'git status'
]);

$info = $gitInfo->getInfo('status');
// $info = THE STATUS
```

**Using `static` method:**

```
// Add the status command
GitInfo::addCommand('status', 'git status');

// All instances of GitInfo (existing and newly created) will now have a status command
$gitInfo = new GitInfo();
$info = $gitInfo->getInfo('status');

// $info = THE STATUS
```

Working directory
-----------------

[](#working-directory)

### Set the working directory

[](#set-the-working-directory)

You can set the working directory when instantiating a new instance of `GitInfo`:

```
// When instantiating GitInfo
$gitInfo = new \Grimzy\GitInfo\GitInfo('absolute/or/relative/path');
```

> The default working directory is set using [`getcwd()`](http://php.net/manual/en/function.getcwd.php).

### Get the working directory

[](#get-the-working-directory)

```
$gitInfo = new \Grimzy\GitInfo\GitInfo();
$gwd = $gitInfo->getWorkingDirectory();
// $gwd = '/absolute/path/to/working/directory'
```

Tests
-----

[](#tests)

```
$ composer test
```

Licence
-------

[](#licence)

GitInfo is licensed under the [MIT License](LICENSE).

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 53.4% 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

Unknown

Total

1

Last Release

2442d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a16b5aa623bcbeec36efc77ff13aca2a591670d48cc489d3b1a91c069e23247e?d=identicon)[grimzy](/maintainers/grimzy)

![](https://www.gravatar.com/avatar/7825b86c0ab45c2e9316a9573d63f7e5ba7a69583101b8ed92bcde269038d293?d=identicon)[numaquevedo](/maintainers/numaquevedo)

---

Top Contributors

[![grimzy](https://avatars.githubusercontent.com/u/1837678?v=4)](https://github.com/grimzy "grimzy (31 commits)")[![numaquevedo](https://avatars.githubusercontent.com/u/10319056?v=4)](https://github.com/numaquevedo "numaquevedo (27 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/grimzy-git-info/health.svg)

```
[![Health](https://phpackages.com/badges/grimzy-git-info/health.svg)](https://phpackages.com/packages/grimzy-git-info)
```

PHPackages © 2026

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