PHP code example of ausi / remote-git
1. Go to this page and download the library: Download ausi/remote-git 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/ */
ausi / remote-git example snippets
use Ausi\RemoteGit\Repository;
use Ausi\RemoteGit\GitObject\File;
use Ausi\RemoteGit\Exception\ConnectionException;
use Ausi\RemoteGit\Exception\PushCommitException;
$repo = new Repository('ssh://[email protected]/ausi/remote-git.git');
try {
$repo->connect();
} catch(ConnectionException $exception) {
// Unable to connect to the specified server
}
$headCommit = $repo->getBranch('main')->getCommit();
$newTree = $headCommit
->getTree()
->withFile(
'example.txt',
'Example content…',
)
;
$newCommit = $repo->commitTree($newTree, 'Add example', $headCommit);
try {
$repo->pushCommit($newCommit, 'main');
} catch(PushCommitException $exception) {
// Unable to push to the specified remote, e.g. no write access
}