Readonly Git client implementation, that allows one to clone or read Git repository data without native Git client installed.
- PHP >= 8.2,
- ext-zlib - to properly decompress git objects.
You can interact with Git repository by instantiating GitRepository
class.
$gitRepository = new \Rodziu\Git\GitRepository('/path/to/your/project/.git');
$gitRepository = new \Rodziu\Git\GitRepository('/path/to/your/project/.git');
$head = $gitRepository->getHead();
$head->getCommitHash(); // commit hash that current head points to
$head->getBranch(); // current branch, null if head is detached
$gitRepository = new \Rodziu\Git\GitRepository('/path/to/your/project/.git');
$gitRepository->getBranches(); // returns an array of local branch names
$gitRepository->getBranches(remote: true); // returns an array of remote branch names
$gitRepository = new \Rodziu\Git\GitRepository('/path/to/your/project/.git');
foreach ($gitRepository->getTags() as $tag) {
$tag; // \Rodziu\Git\Objects\Tag or \Rodziu\Git\Objects\AnnotatedTag
$tag->getName();
$tag->getTaggedObjectHash();
...
}
GitRepository->getLog(?string $commitIsh = null): \Generator
If argument is omitted, log will start from current HEAD.
$gitRepository = new \Rodziu\Git\GitRepository('/path/to/your/project/.git');
foreach ($gitRepository->getLog() as $commit) {
$commit; // \Rodziu\Git\Objects\Commit object
$commit->getMessage();
$commit->getCommitDate();
...
}
// get origin/master branch log
$gitRepository->getLog('origin/master');
$gitRepository = new \Rodziu\Git\GitRepository('/path/to/your/project/.git');
$gitRepository->getCommit('commit-hash'); // \Rodziu\Git\Objects\Commit object
...
Give an object a human readable name based on an available ref
$gitRepository = new \Rodziu\Git\GitRepository('/path/to/your/project/.git');
$gitRepository->describe(); // describe current HEAD with annotated tags
$gitRepository->describe('commit-ish', all: true); // describe given ref as in git describe --all
$gitRepository->describe('commit-ish', tags: true); // describe given ref as in git describe --tags
Fetch repository info and all objects up to current HEAD, then checkout its working tree to /destination/path/repository-name
.
\Rodziu\Git\GitRepository::cloneRepository(
'https://your.repository.url/repository-name.git',
'/destination/path/'
);
Update repository data from remote
$gitRepository = new \Rodziu\Git\GitRepository('/path/to/your/project/.git');
$gitRepository->fetch('origin');
Checkout working tree to given branch, tag or commit
$gitRepository = new \Rodziu\Git\GitRepository('/path/to/your/project/.git');
$gitRepository->checkout('commit-ish');