PHP code example of leapt / git-wrapper

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

    

leapt / git-wrapper example snippets


use Leapt\GitWrapper\Repository;
$repository = new Repository('/path/to/the/git/repo');

$repository = Repository::create('/path/to/the/git/repo');

// change current branch to main
$repository->git('checkout main');

// pull from a remote
$repository->git('pull origin main');

// add a remote repo
$repository->git('remote add origin https://github.com/leapt/git-wrapper.git');

echo $repository->git('log --oneline');

$repository->git('unknown'); // this git command does NOT exist: throw GitRuntimeException

$branches = $repository->getBranches();
// returns ['main', 'other_branch']

$branch = $repository->getCurrentBranch();
// returns 'main'

$hasBranch = $repository->hasBranch('main');
// returns true

$tags = $repository->getTags();
// returns ['first_release', 'v2']

$commits = $repository->getCommits(15);
// returns an array of the 15 last commits

    Array
    (
        [0] => Array
            (
                [id] => affb0e84a11b4180b0fa0e5d36bdac73584f0d71
                [tree] => 4b825dc642cb6eb9a060e54bf8d69288fbee4904
                [author] => Array
                    (
                        [name] => ornicar
                        [email] => [email protected]
                    )

                [authored_date] => 2010-09-22 19:17:35 +0200
                [committer] => Array
                    (
                        [name] => ornicar
                        [email] => [email protected]
                    )

                [committed_date] => 2010-09-22 19:17:35 +0200
                [message] => My commit message
            )

        [1] => Array
            (
                ...

$repository = new Repository('/path/to/the/git/repo', true);

$repo = new Repository('/path/to/the/git/repo', false, ['git_executable' => '/usr/bin/git']);

use Leapt\GitWrapper\Repository;
$repository = new Repository('/path/to/the/git/repo', false, ['command_class' => YourCommand::class]);
bash
composer install --working-dir=tools/php-cs-fixer
# Check what can be fixed
tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff
# Fix them
tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --diff