PHPackages                             symplify/git-wrapper - 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. [CLI &amp; Console](/categories/cli)
4. /
5. symplify/git-wrapper

Abandoned → [gitonomy/gitlib](/?search=gitonomy%2Fgitlib)ArchivedLibrary[CLI &amp; Console](/categories/cli)

symplify/git-wrapper
====================

A PHP wrapper around the Git command line utility.

10.2.7(4y ago)36444.1k↓49.4%32MITPHPPHP &gt;=8.0

Since Feb 6Pushed 4y ago1 watchersCompare

[ Source](https://github.com/deprecated-packages/git-wrapper)[ Packagist](https://packagist.org/packages/symplify/git-wrapper)[ Fund](https://www.paypal.me/rectorphp)[ GitHub Sponsors](https://github.com/tomasvotruba)[ RSS](/packages/symplify-git-wrapper/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (8)Versions (187)Used By (2)

PHP Wrapper around GIT
======================

[](#php-wrapper-around-git)

[![Total Downloads](https://camo.githubusercontent.com/0931b25688db9e3127225b488a1bb9d82c557df893f292c2a471b0ff991a1b29/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73796d706c6966792f6769742d777261707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/symplify/git-wrapper)

Git Wrapper provides a **readable API that abstracts challenges of executing Git commands from within a PHP process** for you.

- It's built upon the [`Symfony\Process`](https://symfony.com/doc/current/components/process.html) to execute the Git command with **cross-platform support** and uses the best-in-breed techniques available to PHP.
- This library also provides an SSH wrapper script and API method for developers to **easily specify a private key other than default** by using [the technique from StackOverflow](http://stackoverflow.com/a/3500308/870667).
- Finally, various commands are expected to be executed in the directory containing the working copy. **The library handles this transparently** so the developer doesn't have to think about it.

Install
-------

[](#install)

```
composer require symplify/git-wrapper
```

Usage
-----

[](#usage)

```
use Symplify\GitWrapper\GitWrapper;

// Initialize the library. If the path to the Git binary is not passed as
// the first argument when instantiating GitWrapper, it is auto-discovered.
require_once __DIR__ . '/vendor/autoload.php';

$gitWrapper = new GitWrapper();

// Optionally specify a private key other than one of the defaults
$gitWrapper->setPrivateKey(__DIR__ . '/path/to/private/key');

// Clone a repo into `/path/to/working/copy`, get a working copy object
$git = $gitWrapper->cloneRepository('git://github.com/symplify/git-wrapper.git', __DIR__ . '/path/to/working/copy');

// Create a file in the working copy
touch(__DIR__ . '/path/to/working/copy/text.txt');

// Add it, commit it, and push the change
$git->add(__DIR__ . '/test.txt');
$git->commit('Added the test.txt file as per the examples.');
$git->push();

// Render the output for operation
echo $git->push();

// Stream output of subsequent Git commands in real time to STDOUT and STDERR.
$gitWrapper->streamOutput();

// Execute an arbitrary git command.
// The following is synonymous with `git config -l`
$gitWrapper->git('config -l');
```

All command methods adhere to the following paradigm:

```
$git->command($arg1, $arg2, ..., $options);
```

Replace `command` with the Git command being executed, e.g. `checkout`, `push`, etc. The `$arg*` parameters are a variable number of arguments as they would be passed to the Git command line tool. `$options` is an optional array of command line options in the following format:

```
$options = [
    'verbose' => true,
    // Passes the "--verbose" flag.
    't' => 'my-branch',
    // Passes the "-t my-branch" option.
];
```

#### Logging

[](#logging)

Use the logger listener with [PSR-3](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md) compatible loggers such as [Monolog](https://github.com/Seldaek/monolog) to log commands that are executed.

```
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Symplify\GitWrapper\EventSubscriber\GitLoggerEventSubscriber;

// Log to a file named "git.log"
$logger = new Logger('git');
$logger->pushHandler(new StreamHandler('git.log', Logger::DEBUG));

// Instantiate the subscriber, add the logger to it, and register it.
$gitWrapper->addLoggerEventSubscriber(new GitLoggerEventSubscriber($logger));

$git = $gitWrapper->cloneRepository('git://github.com/symplify/git-wrapper.git', '/path/to/working/copy');

// The "git.log" file now has info about the command that was executed above.
```

Gotchas
-------

[](#gotchas)

There are a few "gotchas" that are out of scope for this library to solve but might prevent a successful implementation of running Git via PHP.

### Missing HOME Environment Variable

[](#missing-home-environment-variable)

Sometimes the `HOME` environment variable is not set in the Git process that is spawned by PHP. This will cause many Git operations to fail. It is advisable to set the `HOME` environment variable to a path outside of the document root that the web server has write access to. Note that this environment variable is only set for the process running Git and NOT the PHP process that is spawns it.

```
$gitWrapper->setEnvVar('HOME', __DIR__ . '/path/to/private/writable/dir');
```

It is important that the storage is persistent as the `~/.gitconfig` file will be written to this location. See the following "gotcha" for why this is important.

### Missing Identity And Configurations

[](#missing-identity-and-configurations)

Many repositories require that a name and email address are specified. This data is set by running `git config [name] [value]` on the command line, and the configurations are usually stored in the `~/.gitconfig file`. When executing Git via PHP, however, the process might have a different home directory than the user who normally runs git via the command line. Therefore no identity is sent to the repository, and it will likely throw an error.

```
// Set configuration options globally.
$gitWrapper->git('config --global user.name "User name"');
$gitWrapper->git('config --global user.email user@example.com');

// Set configuration options per repository.
$git->config('user.name', 'User name');
$git->config('user.email', 'user@example.com');
```

### Commits To Repositories With No Changes

[](#commits-to-repositories-with-no-changes)

Running `git commit` on a repository *with no changes* fails with exception. To prevent that, check changes like:

```
if ($git->hasChanges()) {
    $git->commit('Committed the changes.');
}
```

### Permissions Of The GIT\_SSH Wrapper Script

[](#permissions-of-the-git_ssh-wrapper-script)

On checkout, the bin/git-ssh-wrapper.sh script should be executable. If it is not, git commands will fail if a non-default private key is specified.

```
$ chmod +x ./bin/git-ssh-wrapper.sh
```

### Timeout

[](#timeout)

There is a default timeout of 60 seconds. This might cause "issues" when you use the clone feature of bigger projects or with slow internet.

```
$this->gitWrapper = new GitWrapper();
$this->gitWrapper->setTimeout(120);
```

###  Health Score

44

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community15

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 96.2% 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 ~2 days

Total

186

Last Release

1480d ago

Major Versions

9.4.70 → 10.0.0-beta12021-11-02

PHP version history (2 changes)9.1.0PHP &gt;=7.3

v9.3.27PHP &gt;=8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/924196?v=4)[Tomas Votruba](/maintainers/TomasVotruba)[@TomasVotruba](https://github.com/TomasVotruba)

---

Top Contributors

[![actions-user](https://avatars.githubusercontent.com/u/65916846?v=4)](https://github.com/actions-user "actions-user (330 commits)")[![TomasVotruba](https://avatars.githubusercontent.com/u/924196?v=4)](https://github.com/TomasVotruba "TomasVotruba (13 commits)")

---

Tags

cligitgit wrapper

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.6k38.2k](/packages/matomo-matomo)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

21764.8M1.6k](/packages/drupal-core)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.4M195](/packages/sulu-sulu)[n98/magerun2

Tools for managing Magento projects and installations

927245.1k6](/packages/n98-magerun2)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

744284.3k34](/packages/civicrm-civicrm-core)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.4M506](/packages/shopware-core)

PHPackages © 2026

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