Git.php
Git.php

Library for work with Git repositories in PHP.

Git-PHP (czproject/git-php) is an open-source PHP library created by Jan Pecha that provides an object-oriented wrapper for interacting with Git repositories in PHP applications.

The main features and capabilities of Git-PHP include:

  • System Requirements & Composer Installation: Requires PHP 8.0 or higher along with a system git executable available in the system PATH variable. It installs easily via Composer using composer require czproject/git-php.

  • Repository Initialization & Cloning: Allows opening existing repositories ($git->open()), initializing new local or bare repositories ($git->init()), and cloning remote repositories into custom directory paths ($git->cloneRepository()).

  • Basic File & Staging Operations: Provides native methods to check for uncommitted changes (hasChanges()), stage specific or grouped files (addFile()), stage all changes (addAllChanges()), rename or remove files, create commits (commit()), checkout branches (checkout()), and perform branch merges (merge()).

  • Branch & Tag Management: Supports querying current, local, or all repository branches, creating new branches, and deleting branches. It also allows listing, creating, renaming, and removing repository tags.

  • Commit History & Detailed Metadata: Enables retrieving the latest commit ID (getLastCommitId()) as well as inspecting full commit objects (getCommit()) to access commit subjects, bodies, author details, committer details, and timestamps.

  • Remote Repository Synchronization: Handles remote operations such as fetching (fetch()), pulling (pull()), and pushing (push()), alongside managing remote endpoints via adding (addRemote()), renaming, removing, or updating remote URLs (setRemoteUrl()).

  • Custom Commands & Class Extensibility: Allows executing raw Git CLI subcommands directly via $repo->execute() or extending the core Git and GitRepository classes to define reusable custom repository methods.

  • BSD Licensing: Distributed open-source under the New BSD License.