{"id":24962387,"url":"https://github.com/directorytree/git","last_synced_at":"2025-04-10T21:42:00.426Z","repository":{"id":56969375,"uuid":"301586153","full_name":"DirectoryTree/Git","owner":"DirectoryTree","description":"A featherweight PHP class for calling Git commands.","archived":false,"fork":false,"pushed_at":"2024-04-02T19:53:13.000Z","size":43,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-03-24T19:08:21.921Z","etag":null,"topics":["git"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DirectoryTree.png","metadata":{"files":{"readme":"README.md","changelog":null,"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}},"created_at":"2020-10-06T01:47:53.000Z","updated_at":"2025-02-13T19:37:22.000Z","dependencies_parsed_at":"2024-04-02T20:49:00.412Z","dependency_job_id":"c010da91-163b-4972-a579-87129e392cb8","html_url":"https://github.com/DirectoryTree/Git","commit_stats":{"total_commits":16,"total_committers":1,"mean_commits":16.0,"dds":0.0,"last_synced_commit":"e9ee8898f8aec7e1c85fa1695121e788a71628ed"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DirectoryTree%2FGit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DirectoryTree%2FGit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DirectoryTree%2FGit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DirectoryTree%2FGit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DirectoryTree","download_url":"https://codeload.github.com/DirectoryTree/Git/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248305801,"owners_count":21081561,"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":["git"],"created_at":"2025-02-03T09:00:02.841Z","updated_at":"2025-04-10T21:42:00.405Z","avatar_url":"https://github.com/DirectoryTree.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eGit\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003eA featherweight PHP class for calling git commands on your web server.\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/DirectoryTree/Git/actions\"\u003e\u003cimg src=\"https://img.shields.io/github/actions/workflow/status/directorytree/git/run-tests.yml?branch=main\u0026style=flat-square\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/DirectoryTree/Git\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/DirectoryTree/Git.svg?style=flat-square\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/DirectoryTree/Git\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/DirectoryTree/Git.svg?style=flat-square\"/\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/DirectoryTree/Git\"\u003e\u003cimg src=\"https://img.shields.io/github/license/DirectoryTree/Git.svg?style=flat-square\"/\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Requirements\n\n- PHP \u003e= 7.3\n\n## Installation\n\n```bash\ncomposer require directorytree/git\n```\n\nBefore getting started, you must ensure you change PHP's working directory to the root of your Git repository using `chdir()`:\n\n```php\n// The current working directory:\nchdir(getcwd());\n\n// A specific directory:\nchdir('/usr/sbin/httpd');\n```\n\nThis package also assumes that Git has been installed and is available in your systems `PATH`, so it can be called globally.\n\n## Usage\n\nCreate a new `Git` instance, and set the remote you want to work with:\n\n```php\nuse DirectoryTree\\Git\\Git;\n\n$git = new Git($remote = 'origin');\n```\n\n### Available Commands\n\n#### Pull\n\nReturns `true` or `false`.\n\n```php\n$git = new Git();\n\n$successful = $git-\u003epull('master');\n\n$successful = $git-\u003epull('v1.0.1');\n```\n\n#### Fetch\n\nReturns `true` or `false`.\n\n```php\n$git = new Git();\n\n$successful = $git-\u003efetch();\n```\n\n#### Reset\n\nReturns `true` or `false`.\n\n\u003e Note: A `hard` reset will always be performed by default unless specified otherwise.\n\n```php\n$git = new Git();\n\n$successful = $git-\u003ereset($commitOrTag = 'v0.0.9');\n\n$successful = $git-\u003ereset($commitOrTag = 'v0.0.9', $mode = 'soft');\n```\n\n#### Remotes\n\n##### Get\n\nReturns an `array` of remote URLs (empty array on failure):\n\n```php\n$urls = $git-\u003egetRemote('origin');\n```\n\n##### Get All\n\nReturns an `array` of remotes, with their URLs (empty array on failure):\n\n```php\n$remotes = $git-\u003egetRemotes();\n```\n\n##### Add\n\nReturns `true` or `false`.\n\n```php\n$success = $git-\u003eaddRemote('origin', 'https://github.com/DirectoryTree/Git');\n```\n\n##### Set URL\n\nReturns `true` or `false`.\n\n```php\n$successful = $git-\u003esetRemoteUrl('origin', 'https://github.com/DirectoryTree/Git');\n```\n\n##### Remove \n\nReturns `true` or `false`.\n\n```php\n$successful = $git-\u003eremoveRemote('origin');\n```\n\n#### Tags\n\n##### Get All \n\nReturns an `array` of tags (empty `array` on failure):\n\n```php\n$tags = $git-\u003egetTags();\n```\n\n##### Get Current\n\nReturns the current repository's tag (`false` on failure).\n\n```php\n$currentTag = $git-\u003egetCurrentTag();\n```\n\n##### Get Latest\n\nReturns the current repository's latest (`false` on failure).\n\n```php\n$latestTag = $git-\u003egetLatestTag();\n```\n\n##### Get Next\n\nReturns the current repository's tag that is directly after the given (`false` on failure).\n\n```php\n$nextTag = $git-\u003egetNextTag('v1.0.0');\n```\n\n##### Get Previous\n\n```php\n$previousTag = $git-\u003egetPreviousTag('v1.0.1');\n```\n\n#### Commits\n\n#### Get All\n\nReturns an `array` of commits (empty `array` on failure):\n\n```php\n$commits = $git-\u003egetCommits();\n\n$commits = $git-\u003egetCommits(['from' =\u003e '9d26e0']);\n\n$commits = $git-\u003egetCommits(['from' =\u003e '9d26e0', 'to' =\u003e '8bf0de6']);\n```\n\n##### Get Between\n\nShorthand for the above method.\n\n```php\n$commits = $git-\u003egetCommitsBetween($from = '9d26e0', $to = '8bf0de6');\n```\n\n## Testing\n\nGit uses the PHP package [TitasGailius/terminal](https://github.com/TitasGailius/terminal) for\nrunning all commands. This means you can utilize it's testing framework for executing all Git commands:\n\n```php\nuse DirectoryTree\\Git\\Git;\n\nclass GitTest extends TestCase\n{\n    public function test_git_pull()\n    {\n        Terminal::fake([\n            'git pull {{ $remote }} {{ $commit }} --ff-only' =\u003e Terminal::response()-\u003esuccessful()\n        ]);\n\n        $this-\u003eassertTrue((new Git)-\u003epull('v1.0.0'));\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirectorytree%2Fgit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdirectorytree%2Fgit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdirectorytree%2Fgit/lists"}