- How do I install markwalet/laravel-git-state in my Laravel app?
- Install it with Composer by running composer require markwalet/laravel-git-state. The package ships a service provider that is auto-discovered, so you typically do not need to register anything manually in config/app.php. After installing, publish the config file with php artisan vendor:publish to select the git driver and point it at your repository. Check the declared PHP and Laravel constraints in the package's composer.json first to confirm your versions are supported.
- How do I get the current git branch and commit hash in Laravel?
- Resolve the package's manager from the container or via its facade, then call the methods that read the current branch, commit hash, tag, and dirty status. Because the package follows Laravel's manager-plus-drivers pattern, the same API works whether it is backed by a real git driver or the fake one. That makes it straightforward to surface the branch and short commit hash on a dashboard, a health endpoint, or a deployment banner.
- Which Laravel and PHP versions does this package support?
- The supported matrix is declared in the package's composer.json, so check the illuminate/support and php constraints there before upgrading. Release v1.11.2 is a patch that restores the FakeGitDriver and does not change framework requirements by itself. The package constraints are the source of truth, so verify compatibility on a branch if your application is on an older Laravel line.
- How do I configure the driver and repository path?
- Publish the config file with php artisan vendor:publish and set the driver plus the repository path the package should inspect. The driver layer is pluggable, with real git drivers and a FakeGitDriver, so config is where you switch between them. Path and credential settings belong in the published config or your env file rather than hard-coded in application code. Run php artisan config:cache in production once the values are final.
- How do I fake git state in my tests without a real repository?
- Use the FakeGitDriver to stub git responses so your test suite does not need a real repository, credentials, or a git binary on the CI host. FakeGitDriver was restored in v1.11.2, so teams that wrote their own test double to replace the missing class can delete it and switch back. Before relying on it, check which methods the fake implements and confirm it matches the public contract of the real drivers you use in production.
- Does this package require the git binary to be installed on the server?
- Yes. The real drivers shell out to git, so the binary must exist and be on the PATH of the process running PHP. That is usually fine on virtual machines and build agents, but it is a problem on distroless images or hosts with read-only filesystems. If your runtime cannot run git, capture the version at build time and inject it as an environment variable instead.
- How is the dirty working tree status determined?
- The dirty flag reflects whether the working tree has uncommitted changes, which the real drivers determine by running git status against the configured repository path. Because it inspects the actual working directory, the result depends on filesystem permissions and on what is checked out on that host. In immutable deployments the checkout is normally clean, so dirty status is most useful in staging or local environments.
- Is it safe to use this package in production?
- The package only reads repository metadata, so it is low risk in production provided the git binary exists and the application user can read the repository path. The real concerns are subprocess cost and concurrency: avoid shelling out to git on every request in a high-traffic app, and cache the values instead. Also make sure the deployment user can read the working tree without exposing credentials or SSH keys to the web process.
- Is markwalet/laravel-git-state actively maintained?
- It is a small, focused package with a conventional Laravel architecture, so the surface area that needs maintaining is limited. The v1.11.2 patch restored the FakeGitDriver and re-enabled its test coverage, which is a reasonable signal of ongoing care. As with any single-maintainer package, check recent release cadence on the repository and keep a fallback in mind, such as a build-time version file or a few lines of exec.
- What are the alternatives to using a Laravel git package?
- You can read git metadata yourself with exec('git rev-parse HEAD') or by parsing a version file generated during your build, which removes the dependency but loses the driver abstraction and test seam. Other Laravel git-info packages exist, so compare their supported Laravel and PHP versions, testability, and release cadence. If all you need is a version string, an environment variable baked in at deploy time is the simplest and most portable option.