Git abstraction layer written in PHP
Warning
This project is not finished yet, work in progress.
You can install the package via composer:
composer require ghostwriter/git
You can also star (🌟) this repo to find it easier later.
use Ghostwriter\Git\Git;
use Ghostwriter\Git\EnvironmentVariables;
use Ghostwriter\Git\Repository;
// Path to the repository
$path = '/path/to/repo';
// Environment variables
$env = [
'GIT_AUTHOR_NAME' => 'John Doe',
'GIT_AUTHOR_EMAIL' => '[email protected]',
'HOME' => '/path/to/home',
'PATH' => '/usr/local/bin:/usr/bin:/bin',
];
// Initialize and return a Git instance
$git = Git::new($path, $env);
// Or use composition
$environmentVariables = EnvironmentVariables::new($env);
$repository = Repository::new($path);
$git = new Git($repository, $environmentVariables);
// ==============================
// Initialize and return a RepositoryInterface instance
$git->init();
// Clone and return a RepositoryInterface instance
$git->clone('git://github.com/ghostwriter/git.git', '/path/to/repo');
// Add a file to the index
$git->add('file.txt');
$git->add('file.txt', 'file2.txt');
// Commit changes
$git->commit('Initial commit');
// Push changes
$git->push('origin', 'main');
// Pull changes
$git->pull('origin', 'main');
// Fetch changes
$git->fetch('origin');
// Merge changes
$git->merge('origin/main');
// Checkout branch
$git->checkout('main');
// Create a new branch
$git->branch('new-branch');
// Delete a branch
$git->deleteBranch('new-branch');
// List branches
$git->branches();
// Get the current branch
$git->currentBranch();
// Get the repository status
$git->status();
// Switch branch
$git->switch('feature-branch');
// Get the repository log
$git->log();
// Get the repository diff
$git->diff();
Please see CHANGELOG.md for more information on what has changed recently.
Please see LICENSE for more information on the license that applies to this project.
Please see SECURITY.md for more information on security disclosure process.