innmind / git
Git abstraction
3.2.0
2023-09-23 12:52 UTC
Requires
- php: ~8.2
- innmind/immutable: ~4.0|~5.0
- innmind/server-control: ~4.1|~5.0
- innmind/time-continuum: ~3.0
- innmind/url: ~4.0
Requires (Dev)
- innmind/black-box: ~5.5
- innmind/coding-standard: ~2.0
- innmind/operating-system: ^3.0
- phpunit/phpunit: ~10.2
- symfony/filesystem: ~6.0
- vimeo/psalm: ~5.12
README
Abstraction layer to manipulate local git repositories.
Feel free to submit a PR to add other git functionalities.
Installation
composer require innmind/git
Usage
use Innmind\Git\{ Git, Repository\Remote\Name, Repository\Remote\Url, Revision\Branch, }; use Innmind\OperatingSystem\Factory; use Innmind\Url\Path; $os = Factory::build(); $git = Git::of($os->control(), $os->clock()); $repository = $git->repository(Path::of('/somewhere/on/the/local/machine'))->match( static fn($repository) => $repository, static fn() => throw new \RuntimeException('The path does not exist'), ); $_ = $repository->init()->match( static fn() => null, // pass static fn() => throw new \RuntimeException('Failed to init the repository'), ); $remotes = $repository->remotes(); $remotes->add(Name::of('origin'), Url::of('git@github.com:Vendor/Repo.git')) $remotes->push(Branch::of('master')); $repository ->branches() ->new(Branch::of('develop')); $repository ->checkout() ->revision(Branch::of('develop'));
This example initialize a local git repository, declare a github repository as its remote and finally checkout the new branch develop
.
The offered functionalities goes beyond this single example, check the classes' interface to discover all of them.