PHP code example of vestnik / phpgit

1. Go to this page and download the library: Download vestnik/phpgit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vestnik / phpgit example snippets


$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->merge('1.0');
$git->merge('1.1', 'Merge message', ['strategy' => 'ours']);

$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
try {
    $git->merge('dev');
} catch (PHPGit\Exception\GitException $e) {
    $git->merge->abort();
}
 php


w PHPGit\Git();
$git->clone('https://github.com/kzykhys/PHPGit.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
$git->remote->add('production', 'git://example.com/your/repo.git');
$git->add('README.md');
$git->commit('Adds README.md');
$git->checkout('release');
$git->merge('master');
$git->push();
$git->push('production', 'release');
$git->tag->create('v1.0.1', 'release');

foreach ($git->tree('release') as $object) {
    if ($object['type'] == 'blob') {
        echo $git->show($object['file']);
    }
}
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->add('file.txt');
$git->add('file.txt', ['force' => false, 'ignore-errors' => false);
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$branches = $git->branch();
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->branch->move('bugfix', '2.0');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->branch->delete('2.0');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$contents = $git->cat->blob('e69de29bb2d1d6434b8b29ae775ad8');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$type = $git->cat->type('e69de29bb2d1d6434b8b29ae775ad8');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$type = $git->cat->size('e69de29bb2d1d6434b8b29ae775ad8');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->checkout('develop');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->checkout->create('patch-1');
$git->checkout->create('patch-2', 'develop');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->checkout->orphan('gh-pages');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->tag->create('v1.0.0');
$git->commit('Fixes #14');
echo $git->describe('HEAD', ['tags' => true]);
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'git://your/repo.git');
$git->fetch('origin');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'git://your/repo.git');
$git->remote->add('release', 'git://your/another_repo.git');
$git->fetch->all();
 php
$git = new PHPGit\Git();
$git->init('/path/to/repo1');
$git->init('/path/to/repo2', array('shared' => true, 'bare' => true));
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$logs = $git->log(array('limit' => 10));
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->mv('UPGRADE-1.0.md', 'UPGRADE-1.1.md');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->pull('origin', 'master');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->push('origin', 'master');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->fetch('origin');
$git->rebase('origin/master');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->fetch('origin');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->rename('origin', 'upstream');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->rm('origin');
 php
$git = new PHPGit\Git();
$git->clone('https://github.com/kzykhys/Text.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
echo $git->remote->show('origin');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->prune('origin');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->head('origin');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->head->set('origin');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->head->delete('origin');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->head->remote('origin');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->branches('origin', array('master', 'develop'));
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->branches->set('origin', array('master', 'develop'));
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->remote->add('origin', 'https://github.com/kzykhys/Text.git');
$git->remote->branches->add('origin', array('master', 'develop'));
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset();
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->soft();
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->mixed();
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->hard();
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->merge();
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->keep();
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->reset->mode('hard');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->rm('CHANGELOG-1.0-1.1.txt', ['force' => true]);
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$shortlog = $git->shortlog();
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$shortlog = $git->shortlog->summary();
 php
[
    'John Doe <[email protected]>' => 153,
    //...
]
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
echo $git->show('3ddee587e209661c8265d5bfd0df999836f6dfa2');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash();
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->save('My stash');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$stashes = $git->stash->lists();
 php
[
    0 => ['branch' => 'master', 'message' => '0e2f473 Fixes README.md'],
    1 => ['branch' => 'master', 'message' => 'ce1ddde Initial commit'],
]
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
echo $git->stash->show('stash@{0}');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->drop('stash@{0}');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->pop('stash@{0}');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->apply('stash@{0}');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->branch('hotfix', 'stash@{0}');
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->stash->clear();
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$commit = $git->stash->create();
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$status = $git->status();
 php
[
    'branch' => 'master',
    'changes' => [
        ['file' => 'item1.txt', 'index' => 'A', 'work_tree' => 'M'],
        ['file' => 'item2.txt', 'index' => 'A', 'work_tree' => ' '],
        ['file' => 'item3.txt', 'index' => '?', 'work_tree' => '?'],
    ]
]
 php
$git = new PHPGit\Git();
$git->setRepository('/path/to/repo');
$git->tag->create('v1.0.0');