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

Abandoned → [symplify/git-wrapper](/?search=symplify%2Fgit-wrapper)ArchivedLibrary[CLI &amp; Console](/categories/cli)

cpliakas/git-wrapper
====================

A PHP wrapper around the Git command line utility.

3.1.0(5y ago)4981.7M↓27.9%67[1 issues](https://github.com/cpliakas/git-wrapper/issues)20MITPHPPHP &gt;=7.3CI failing

Since Jan 10Pushed 5y ago20 watchersCompare

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

READMEChangelog (1)Dependencies (15)Versions (33)Used By (20)

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

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

[![Total Downloads](https://camo.githubusercontent.com/31e7907bcaa81679f53f803aa86eb9c1e6964bf59d613b9cb0af5965d8dea5b6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f63706c69616b61732f6769742d777261707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cpliakas/git-wrapper)[![Latest Stable Version](https://camo.githubusercontent.com/55915ffcada6883f7dbdbd364e06a2d4115c6d4e2abf2d798ae6aae06f3f50ab/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f63706c69616b61732f6769742d777261707065722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/cpliakas/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 cpliakas/git-wrapper
```

Usage
-----

[](#usage)

```
use 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('/path/to/private/key');

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

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

// Add it, commit it, and push the change
$git->add('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.

```
