2017 © Pedro Peláez
 

library git-php

Easy to use GIT wrapper for PHP.

image

bit3/git-php

Easy to use GIT wrapper for PHP.

  • Thursday, March 9, 2017
  • by tril
  • Repository
  • 2 Watchers
  • 11 Stars
  • 24,050 Installations
  • PHP
  • 7 Dependents
  • 0 Suggesters
  • 7 Forks
  • 1 Open issues
  • 10 Versions
  • 6 % Grown

The README.md

Build Status Latest Version tagged Latest Version on Packagist Installations via composer per month, (*1)

Easy to use GIT wrapper for php

This is a lightweight wrapper, providing the git commands in PHP., (*2)

Usage examples

The API use command builders, that allow you to build a command and execute it one time., (*3)

The main synopsis is:, (*4)

$git->command()->option()->execute();

$git->command() will create a new command, *->option() will add an option to the command and *->execute() will finally execute the command., (*5)

The naming of commands and options follow the git naming. If you search for documentation of a specific command or option, just look into the git documentation. You will find the command/option there., (*6)

init a new git repository

use Bit3\GitPhp\GitRepository;

$directory = '/path/to/git/target/directory';

$git = new GitRepository($directory);
$git->init()->execute();

clone a git repository

The clone command is named cloneRepository() because clone is a reserved word in PHP., (*7)

use Bit3\GitPhp\GitRepository;

$directory = '/path/to/git/target/directory';

$git = new GitRepository($directory);
$git->cloneRepository()->execute();

describe

$annotatedTag   = $git->describe()->execute();
$lightweightTag = $git->describe()->tags()->execute();
$recentRef      = $git->describe()->all()->execute();

set remote fetch url

$git->remote()
    ->setUrl('origin', 'git@github.com:bit3/git-php.git')
    ->execute();

set remote push url

$git->remote()
    ->setPushUrl('origin', 'git@github.com:bit3/git-php.git')
    ->execute();

add new remote

$git->remote()
    ->add('github', 'git@github.com:bit3/git-php.git')
    ->execute();

fetch remote objects

$git->fetch()->execute('github');

checkout

$git->checkout()->execute('hotfix/1.2.3');

checkout specific path

$git->checkout()->execute('hotfix/1.2.3', '/fileA', '/fileB', '/dir/fileC');

push objects

$git->push()->execute('github', 'hotfix/1.2.3');

add file to staging index

$git->add()->execute('file/to/add.ext');

remove file

$git->rm()->execute('file/to/remove.ext');

commit changes

$git->commit()->message('Commit message')->execute();

create a tag

$git->tag()->execute('v1.2.3');

Convenience and shortcut methods

list remotes

$remotes = $git->remote()->getNames();

// array(
//     'origin',
//     'composer',
// )

list branches

$remotes = $git->branch()->getNames();

// array(
//     'master',
//     'hotfix/1.2.3',
// )

list remote tracking branches

$remotes = $git->branch()->remotes()->->getNames();

// array(
//     'origin/master',
//     'origin/hotfix/1.2.3',
//     'origin/release/4.5.6',
// )

list branches including remote tracking branches

$remotes = $git->branch()->all()->->getNames();

// array(
//     'master',
//     'hotfix/1.2.3',
//     'remotes/origin/master',
//     'remotes/origin/hotfix/1.2.3',
//     'remotes/origin/release/4.5.6',
// )

get modification status

$status = $git->status()->getStatus();

// array(
//     'existing-file.txt'      => array('index' => 'D',   'worktree' => false),
//     'removed-but-staged.txt' => array('index' => 'D',   'worktree' => 'A'),
//     'staged-file.txt'        => array('index' => false, 'worktree' => 'A'),
//     'unknown-file.txt'       => array('index' => '?',   'worktree' => '?'),
// )

get index modification status

$status = $git->status()->getIndexStatus();

// array(
//     'existing-file.txt'      => 'D',
//     'removed-but-staged.txt' => 'D',
//     'staged-file.txt'        => false,
//     'unknown-file.txt'       => '?',
// )

get worktree modification status

$status = $git->status()->getWorkTreeStatus();

// array(
//     'existing-file.txt'      => 'worktree' => false,
//     'removed-but-staged.txt' => 'worktree' => 'A',
//     'staged-file.txt'        => 'worktree' => 'A',
//     'unknown-file.txt'       => 'worktree' => '?',
// )

The Versions

09/03 2017

dev-develop

dev-develop

Easy to use GIT wrapper for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

09/03 2017

dev-master

9999999-dev

Easy to use GIT wrapper for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

09/03 2017

1.4.1

1.4.1.0

Easy to use GIT wrapper for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

07/02 2017

1.4.0

1.4.0.0

Easy to use GIT wrapper for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

07/07 2016

1.3.0

1.3.0.0

Easy to use GIT wrapper for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

08/09 2015

1.2.1

1.2.1.0

Easy to use GIT wrapper for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

08/09 2015

1.2.0

1.2.0.0

Easy to use GIT wrapper for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires

05/08 2015

1.1.1

1.1.1.0

Easy to use GIT wrapper for PHP.

  Sources   Download

MIT

The Requires

 

The Development Requires