PHP code example of pvpender / git-kphp

1. Go to this page and download the library: Download pvpender/git-kphp 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/ */

    

pvpender / git-kphp example snippets


use pvpender\GitKphp\Systemc;
Systemc::load();

use pvpender\GitKphp\Git;
use pvpender\GitKphp\Systemc;

Systemc::load();
$git = new pvpender\GitKphp\Git;
// create repo object
$repo = $git->open(__DIR__);

// or you can just clone repo
// $repo = $git->cloneRepository('https://github.com/user/repo');

// create a new file in repo
$filename = $repo->getRepositoryPath() . '/newfile.txt';
file_put_contents($filename, "Hello world!");

// commit
$repo->addFile($filename);
$repo->commit('init commit');
 php
$repo = $git->init('/path/to/repo-directory');
 php
$repo = $git->init('/path/to/repo-directory', [
	'--bare', // creates bare repo
]);
 php
$repo->commit('commit message');
$repo->merge('branch-name');
$repo->checkout('master');
$repo->getRepositoryPath();
// adds files into commit
$repo->addFile('file.txt');
$repo->addFile('file1.txt', 'file2.txt');
$repo->addFile(['file3.txt', 'file4.txt']);
// renames files in repository
$repo->renameFile('old.txt', 'new.txt');
$repo->renameFile([
    'old1.txt' => 'new1.txt',
    'old2.txt' => 'new2.txt',
]);
// removes files from repository
$repo->removeFile('file.txt');
$repo->removeFile('file1.txt', 'file2.txt');
$repo->removeFile(['file3.txt', 'file4.txt']);
// adds all changes in repository
$repo->addAllChanges();