PHP code example of directorytree / git

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

    

directorytree / git example snippets


// The current working directory:
chdir(getcwd());

// A specific directory:
chdir('/usr/sbin/httpd');

use DirectoryTree\Git\Git;

$git = new Git($remote = 'origin');

$git = new Git();

$successful = $git->pull('master');

$successful = $git->pull('v1.0.1');

$git = new Git();

$successful = $git->fetch();

$git = new Git();

$successful = $git->reset($commitOrTag = 'v0.0.9');

$successful = $git->reset($commitOrTag = 'v0.0.9', $mode = 'soft');

$urls = $git->getRemote('origin');

$remotes = $git->getRemotes();

$success = $git->addRemote('origin', 'https://github.com/DirectoryTree/Git');

$successful = $git->setRemoteUrl('origin', 'https://github.com/DirectoryTree/Git');

$successful = $git->removeRemote('origin');

$tags = $git->getTags();

$currentTag = $git->getCurrentTag();

$latestTag = $git->getLatestTag();

$nextTag = $git->getNextTag('v1.0.0');

$previousTag = $git->getPreviousTag('v1.0.1');

$commits = $git->getCommits();

$commits = $git->getCommits(['from' => '9d26e0']);

$commits = $git->getCommits(['from' => '9d26e0', 'to' => '8bf0de6']);

$commits = $git->getCommitsBetween($from = '9d26e0', $to = '8bf0de6');

use DirectoryTree\Git\Git;

class GitTest extends TestCase
{
    public function test_git_pull()
    {
        Terminal::fake([
            'git pull {{ $remote }} {{ $commit }} --ff-only' => Terminal::response()->successful()
        ]);

        $this->assertTrue((new Git)->pull('v1.0.0'));
    }
}