{"id":19719421,"url":"https://github.com/leapt/git-wrapper","last_synced_at":"2025-06-14T19:37:59.659Z","repository":{"id":57013376,"uuid":"342168691","full_name":"leapt/git-wrapper","owner":"leapt","description":"Provides an object oriented wrapper to run any Git command. For PHP 8.0+.","archived":false,"fork":false,"pushed_at":"2023-12-05T10:12:14.000Z","size":103,"stargazers_count":1,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"2.x","last_synced_at":"2025-05-01T08:48:49.378Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"ornicar/php-git-repo","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/leapt.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-02-25T08:07:34.000Z","updated_at":"2024-12-20T13:26:38.000Z","dependencies_parsed_at":"2023-12-05T10:47:48.292Z","dependency_job_id":"d2d0dbf7-0194-4098-b967-e9f5f80b5167","html_url":"https://github.com/leapt/git-wrapper","commit_stats":{"total_commits":75,"total_committers":9,"mean_commits":8.333333333333334,"dds":0.4933333333333333,"last_synced_commit":"b2144d8ad25793cc8bc69120f1b9b3d15c970c10"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/leapt/git-wrapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leapt%2Fgit-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leapt%2Fgit-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leapt%2Fgit-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leapt%2Fgit-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/leapt","download_url":"https://codeload.github.com/leapt/git-wrapper/tar.gz/refs/heads/2.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/leapt%2Fgit-wrapper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259480629,"owners_count":22864418,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T23:08:14.865Z","updated_at":"2025-06-14T19:37:59.640Z","avatar_url":"https://github.com/leapt.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Leapt Git Wrapper\n\n[![Package version](https://img.shields.io/packagist/v/leapt/git-wrapper.svg?style=flat-square)](https://packagist.org/packages/leapt/git-wrapper)\n[![Build Status](https://img.shields.io/github/actions/workflow/status/leapt/git-wrapper/continuous-integration.yml?branch=main\u0026style=flat-square)](https://github.com/leapt/git-wrapper/actions?query=workflow%3A%22Continuous+Integration%22)\n![PHP Version](https://img.shields.io/packagist/php-v/leapt/git-wrapper.svg?branch=main\u0026style=flat-square)\n[![License](https://img.shields.io/badge/license-MIT-red.svg?style=flat-square)](LICENSE)\n[![Code coverage](https://img.shields.io/codecov/c/github/leapt/git-wrapper?style=flat-square)](https://codecov.io/gh/leapt/git-wrapper/branch/main)\n\nAllows to manage a Git repository with PHP.\nProvides an object-oriented wrapper to run any Git command.\n\n## Requirements\n\n- PHP \u003e= 8.2\n- Git \u003e= 1.5\n\n## Instantiate a Repository\n\n```php\nuse Leapt\\GitWrapper\\Repository;\n$repository = new Repository('/path/to/the/git/repo');\n```\n\nIt does NOT create a Git repo, but a PHP object to manipulate an existing Git repo.\n\n## Create a Git repository\n\nIf the Git repository does not exist yet on file system, `Repository` can create it for you.\n\n```php\n$repository = Repository::create('/path/to/the/git/repo');\n```\n\nIt runs `git init` and returns a `Repository` object.\n\n## Run git commands\n\n`git` commands can be run with the same syntax as in the CLI. Some examples:\n\n```php\n// change current branch to main\n$repository-\u003egit('checkout main');\n\n// pull from a remote\n$repository-\u003egit('pull origin main');\n\n// add a remote repo\n$repository-\u003egit('remote add origin https://github.com/leapt/git-wrapper.git');\n```\n\nThere are no limitations, you can run any git commands.\n\nThe `git()` method returns the output string:\n\n```php\necho $repository-\u003egit('log --oneline');\n```\n\n```\ne30b70b Move test repo to system tmp dir, introduce PHPGit_Command\n01fabb1 Add test repo\n12a95e6 Add base class with basic unit test\n58e7769 Fix readme\nc14c9ec Initial commit\n```\n\nThe `git()` method throws a `GitRuntimeException` if the command is invalid:\n\n```php\n$repository-\u003egit('unknown'); // this git command does NOT exist: throw GitRuntimeException\n```\n\n## Get branches information\n\nSome shortcut methods are provided to deal with branches in a convenient way.\n\n### Get the branches list\n\n```php\n$branches = $repository-\u003egetBranches();\n// returns ['main', 'other_branch']\n```\n\n### Get the current branch\n\n```php\n$branch = $repository-\u003egetCurrentBranch();\n// returns 'main'\n```\n\n### Know if the repo has a given branch\n\n```php\n$hasBranch = $repository-\u003ehasBranch('main');\n// returns true\n```\n\n## Get tags information\n\n### Get the tags list:\n\n```php\n$tags = $repository-\u003egetTags();\n// returns ['first_release', 'v2']\n```\n\n## Get commits information\n\nYou can get an array of the last commits on the current branch.\n\n```php\n$commits = $repository-\u003egetCommits(15);\n// returns an array of the 15 last commits\n```\n\nInternally, this method runs `git log` with formatted output. The return value should look like:\n\n```php\n    Array\n    (\n        [0] =\u003e Array\n            (\n                [id] =\u003e affb0e84a11b4180b0fa0e5d36bdac73584f0d71\n                [tree] =\u003e 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n                [author] =\u003e Array\n                    (\n                        [name] =\u003e ornicar\n                        [email] =\u003e myemail@gmail.com\n                    )\n\n                [authored_date] =\u003e 2010-09-22 19:17:35 +0200\n                [committer] =\u003e Array\n                    (\n                        [name] =\u003e ornicar\n                        [email] =\u003e myemail@gmail.com\n                    )\n\n                [committed_date] =\u003e 2010-09-22 19:17:35 +0200\n                [message] =\u003e My commit message\n            )\n\n        [1] =\u003e Array\n            (\n                ...\n```\n\nThe first commit is the most recent one.\n\nYou can also retrieve the last commit by calling `$repository-\u003egetLastCommit()`.\n\n## Debug mode\n\n`Repository` constructor's second parameter lets you enable debug mode.\nWhen debug mode is on, commands and their output are displayed.\n\n```php\n$repository = new Repository('/path/to/the/git/repo', true);\n```\n\n## Configure\n\n`Repository` can be configured by passing an array of options to the constructor's third parameter.\n\n### Change git executable path\n\nYou may need to provide the path to the git executable.\n\n```php\n$repo = new Repository('/path/to/the/git/repo', false, ['git_executable' =\u003e '/usr/bin/git']);\n```\n\nOn most Unix system, it's `/usr/bin/git`. On Windows, it may be `C:\\Program Files\\Git\\bin`.\n\n### Change the command class\n\nBy default, the `Repository` class will use the `Command` class to implement Git commands.\nBy replacing this option, you can use your own command implementation\n(which must implement the `Leapt\\GitWrapper\\CommandInterface`):\n\n```php\nuse Leapt\\GitWrapper\\Repository;\n$repository = new Repository('/path/to/the/git/repo', false, ['command_class' =\u003e YourCommand::class]);\n```\n\n## Contributing\n\nFeel free to contribute, like sending [pull requests](https://github.com/leapt/git-wrapper/pulls) to add features/tests\nor [creating issues](https://github.com/leapt/git-wrapper/issues) :)\n\nNote there are a few helpers to maintain code quality, that you can run using these commands:\n\n### PHPStan\n\n```bash\ncomposer install --working-dir=tools/phpstan\ntools/phpstan/vendor/bin/phpstan analyze\n```\n\n### PHP CS Fixer\n\n```bash\ncomposer install --working-dir=tools/php-cs-fixer\n# Check what can be fixed\ntools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run --diff\n# Fix them\ntools/php-cs-fixer/vendor/bin/php-cs-fixer fix --diff\n```\n\n### PHPUnit\n\n```bash\nvendor/bin/phpunit # Run tests\ncomposer test # An alias to run tests\n```\n\nNote: tests rely on the default branch being `main`. This can be updated using the following command:\n\n```bash\ngit config --global init.defaultBranch main\n```\n\n## History\n\nThis package is a maintained fork of the [ornicar/php-git-repo](https://github.com/ornicar/php-git-repo) package.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleapt%2Fgit-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleapt%2Fgit-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleapt%2Fgit-wrapper/lists"}