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

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

directorytree/git
=================

Call Git commands using PHP

v1.1.0(2y ago)2441MITPHPPHP ^7.3|^8.0

Since Oct 6Pushed 2y ago2 watchersCompare

[ Source](https://github.com/DirectoryTree/Git)[ Packagist](https://packagist.org/packages/directorytree/git)[ RSS](/packages/directorytree-git/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Git
===

[](#git)

A featherweight PHP class for calling git commands on your web server.

[![](https://camo.githubusercontent.com/e49daf5d9a3deb2701029d238093d3e75a25e3746de2e5b4a0beed701ffb96d2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6469726563746f7279747265652f6769742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e267374796c653d666c61742d737175617265)](https://github.com/DirectoryTree/Git/actions)[![](https://camo.githubusercontent.com/75a13a5041c4743afa7489e1542a9828057a03f247b1fb29dce3c1ba016a66ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f4469726563746f7279547265652f4769742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/DirectoryTree/Git)[![](https://camo.githubusercontent.com/fa9c8a7a7dae06f265f978298648c0c386ced76170d58b3b57fbf639ad09c632/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f4469726563746f7279547265652f4769742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/DirectoryTree/Git)[![](https://camo.githubusercontent.com/d3b73836e5855c017990bd2e1497318eaeab4505ebe7adf5cd108e9f42cfa48b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f4469726563746f7279547265652f4769742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/DirectoryTree/Git)

Requirements
------------

[](#requirements)

- PHP &gt;= 7.3

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

[](#installation)

```
composer require directorytree/git
```

Before getting started, you must ensure you change PHP's working directory to the root of your Git repository using `chdir()`:

```
// The current working directory:
chdir(getcwd());

// A specific directory:
chdir('/usr/sbin/httpd');
```

This package also assumes that Git has been installed and is available in your systems `PATH`, so it can be called globally.

Usage
-----

[](#usage)

Create a new `Git` instance, and set the remote you want to work with:

```
use DirectoryTree\Git\Git;

$git = new Git($remote = 'origin');
```

### Available Commands

[](#available-commands)

#### Pull

[](#pull)

Returns `true` or `false`.

```
$git = new Git();

$successful = $git->pull('master');

$successful = $git->pull('v1.0.1');
```

#### Fetch

[](#fetch)

Returns `true` or `false`.

```
$git = new Git();

$successful = $git->fetch();
```

#### Reset

[](#reset)

Returns `true` or `false`.

> Note: A `hard` reset will always be performed by default unless specified otherwise.

```
$git = new Git();

$successful = $git->reset($commitOrTag = 'v0.0.9');

$successful = $git->reset($commitOrTag = 'v0.0.9', $mode = 'soft');
```

#### Remotes

[](#remotes)

##### Get

[](#get)

Returns an `array` of remote URLs (empty array on failure):

```
$urls = $git->getRemote('origin');
```

##### Get All

[](#get-all)

Returns an `array` of remotes, with their URLs (empty array on failure):

```
$remotes = $git->getRemotes();
```

##### Add

[](#add)

Returns `true` or `false`.

```
$success = $git->addRemote('origin', 'https://github.com/DirectoryTree/Git');
```

##### Set URL

[](#set-url)

Returns `true` or `false`.

```
$successful = $git->setRemoteUrl('origin', 'https://github.com/DirectoryTree/Git');
```

##### Remove

[](#remove)

Returns `true` or `false`.

```
$successful = $git->removeRemote('origin');
```

#### Tags

[](#tags)

##### Get All

[](#get-all-1)

Returns an `array` of tags (empty `array` on failure):

```
$tags = $git->getTags();
```

##### Get Current

[](#get-current)

Returns the current repository's tag (`false` on failure).

```
$currentTag = $git->getCurrentTag();
```

##### Get Latest

[](#get-latest)

Returns the current repository's latest (`false` on failure).

```
$latestTag = $git->getLatestTag();
```

##### Get Next

[](#get-next)

Returns the current repository's tag that is directly after the given (`false` on failure).

```
$nextTag = $git->getNextTag('v1.0.0');
```

##### Get Previous

[](#get-previous)

```
$previousTag = $git->getPreviousTag('v1.0.1');
```

#### Commits

[](#commits)

#### Get All

[](#get-all-2)

Returns an `array` of commits (empty `array` on failure):

```
$commits = $git->getCommits();

$commits = $git->getCommits(['from' => '9d26e0']);

$commits = $git->getCommits(['from' => '9d26e0', 'to' => '8bf0de6']);
```

##### Get Between

[](#get-between)

Shorthand for the above method.

```
$commits = $git->getCommitsBetween($from = '9d26e0', $to = '8bf0de6');
```

Testing
-------

[](#testing)

Git uses the PHP package [TitasGailius/terminal](https://github.com/TitasGailius/terminal) for running all commands. This means you can utilize it's testing framework for executing all Git commands:

```
use DirectoryTree\Git\Git;

class GitTest extends TestCase
{
    public function test_git_pull()
    {
        Terminal::fake([
            'git pull {{ $remote }} {{ $commit }} --ff-only' => Terminal::response()->successful()
        ]);

        $this->assertTrue((new Git)->pull('v1.0.0'));
    }
}
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~1256 days

Total

2

Last Release

784d ago

PHP version history (2 changes)v1.0.0PHP ^7.3

v1.1.0PHP ^7.3|^8.0

### Community

Maintainers

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

---

Top Contributors

[![stevebauman](https://avatars.githubusercontent.com/u/6421846?v=4)](https://github.com/stevebauman "stevebauman (26 commits)")

---

Tags

git

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[composer/composer

Composer helps you declare, manage and install dependencies of PHP projects. It ensures you have the right stack everywhere.

29.4k187.2M2.6k](/packages/composer-composer)[symfony/event-dispatcher

Provides tools that allow your application components to communicate with each other by dispatching events and listening to them

8.6k985.9M3.4k](/packages/symfony-event-dispatcher)[symfony/polyfill-php80

Symfony polyfill backporting some PHP 8.0+ features to lower PHP versions

1.7k815.2M455](/packages/symfony-polyfill-php80)[symfony/var-exporter

Provides tools to export, instantiate, hydrate, clone and lazy-load PHP objects

2.1k378.1M437](/packages/symfony-var-exporter)[seld/phar-utils

PHAR file format utilities, for when PHP phars you up

875180.0M32](/packages/seld-phar-utils)[dansmith/laravel5-foundation

Zurb Foundation components for Laravel5

104.6k](/packages/dansmith-laravel5-foundation)

PHPackages © 2026

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