Skip to content
xmarvelxPublic
forked from bit3/git-php

About

[PHP] Easy to use GIT wrapper for php

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

Version ![Stable Build Status](http://img.shields.io/travis/bit3/git-php/master.svg?style=flat-square&label=stable build) ![Upstream Build Status](http://img.shields.io/travis/bit3/git-php/develop.svg?style=flat-square&label=dev build) License Downloads

Easy to use GIT wrapper for php

This is a lightweight wrapper, providing the git commands in PHP.

Usage examples

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

The main synopsis is:

$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.

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.

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.

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