This repository was forked from bit3/git-php at its version 1.5.0.
This is a lightweight wrapper, providing the git commands in PHP.
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.
GitRepository::in('/path/to/git/target/directory')->init()->execute();
The clone
command is named cloneRepository()
because clone
is a reserved word in PHP.
$git = GitRepository::in('/path/to/repo');
$git->cloneRepository()->execute();
$annotatedTag = $git->describe()->execute();
$lightweightTag = $git->describe()->tags()->execute();
$recentRef = $git->describe()->all()->execute();
$git->remote()
->setUrl('origin', '[email protected]:bit3/git-php.git')
->execute();
$git->remote()
->setPushUrl('origin', '[email protected]:bit3/git-php.git')
->execute();
$git->remote()
->add('github', '[email protected]:bit3/git-php.git')
->execute();
$git->fetch()->execute('github');
$git->checkout()->execute('hotfix/1.2.3');
$git->checkout()->execute('hotfix/1.2.3', '/fileA', '/fileB', '/dir/fileC');
$git->push()->execute('github', 'hotfix/1.2.3');
$git->add()->execute('file/to/add.ext');
$git->rm()->execute('file/to/remove.ext');
$git->commit()->message('Commit message')->execute();
$git->tag()->execute('v1.2.3');
$remotes = $git->remote()->getNames();
// array(
// 'origin',
// 'composer',
// )
$remotes = $git->branch()->getNames();
// array(
// 'master',
// 'hotfix/1.2.3',
// )
$remotes = $git->branch()->remotes()->getNames();
// array(
// 'origin/master',
// 'origin/hotfix/1.2.3',
// 'origin/release/4.5.6',
// )
$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',
// )
$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' => '?'),
// )
$status = $git->status()->getIndexStatus();
// array(
// 'existing-file.txt' => 'D',
// 'removed-but-staged.txt' => 'D',
// 'staged-file.txt' => false,
// 'unknown-file.txt' => '?',
// )
$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' => '?',
// )