PHPackages                             pvpender/git-kphp - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. pvpender/git-kphp

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

pvpender/git-kphp
=================

Library for work with Git repository in KPHP.

v1.2.0(3y ago)49MITPHPPHP &gt;=7.4

Since Dec 11Pushed 3y ago1 watchersCompare

[ Source](https://github.com/pvpender/git-kphp)[ Packagist](https://packagist.org/packages/pvpender/git-kphp)[ RSS](/packages/pvpender-git-kphp/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

Git-KPHP
========

[](#git-kphp)

[![Total Downloads](https://camo.githubusercontent.com/19c9c6243afdaa58c3b0e3634d2962619bf403bc842dc4e2f7d0cba8d5fac71a/687474703a2f2f706f7365722e707567782e6f72672f707670656e6465722f6769742d6b7068702f646f776e6c6f616473)](https://packagist.org/packages/pvpender/git-kphp)[![PHP Version Require](https://camo.githubusercontent.com/40520ff9b97a9b88890d99cacdcc06c80e853d43d4542baf8a5083052d0db496/687474703a2f2f706f7365722e707567782e6f72672f707670656e6465722f6769742d6b7068702f726571756972652f706870)](https://packagist.org/packages/pvpender/git-kphp)

FFI Library for work with Git repository in KPHP.

[Download a latest package](https://github.com/pvpender/git-kphp/releases) or use [Composer](http://getcomposer.org/):

```
composer require pvpender/git-kphp

```

Library requires PHP 7.4, the latest version of [KPHP](https://github.com/VKCOM/kphp) and `git` client (path to Git must be in system variable `PATH`). Also, if you want use commands, which requires to log in git, you should tune authentication without password using private/public keys or setting `-global` parameter.

**Warning!** This is FFI lib. That's mean that some C cod using to normal working. Before proc\_open will not support, this library use FFI, that can be very unsafe. Don't use this library if safety is very important to you.

Before starting
---------------

[](#before-starting)

This is FFI lib, and it means that you should preload `.c` files before starting working the library. Don't worry everything already in `Systemc` class, you only should write:

```
use pvpender\GitKphp\Systemc;
Systemc::load();
```

At the top of your `main.php` file.

Using
-----

[](#using)

```
use pvpender\GitKphp\Git;
use pvpender\GitKphp\Systemc;

Systemc::load();
$git = new pvpender\GitKphp\Git;
// create repo object
$repo = $git->open(__DIR__);

// or you can just clone repo
// $repo = $git->cloneRepository('https://github.com/user/repo');

// create a new file in repo
$filename = $repo->getRepositoryPath() . '/newfile.txt';
file_put_contents($filename, "Hello world!");

// commit
$repo->addFile($filename);
$repo->commit('init commit');
```

Initialization of empty repository
----------------------------------

[](#initialization-of-empty-repository)

```
$repo = $git->init('/path/to/repo-directory');
```

With parameters:

```
$repo = $git->init('/path/to/repo-directory', [
	'--bare', // creates bare repo
]);
```

Cloning of repository
---------------------

[](#cloning-of-repository)

```
// Cloning of repository into subdirectory 'git-kphp' in current working directory
$repo = $git->cloneRepository('https://github.com/pvpender/git-kphp.git');
// Cloning of repository into own directory
$repo = $git->cloneRepository('https://github.com/pvpender/git-kphp.git', '/path/to/my/subdir');
```

Basic operations
----------------

[](#basic-operations)

```
$repo->commit('commit message');
$repo->merge('branch-name');
$repo->checkout('master');
$repo->getRepositoryPath();
// adds files into commit
$repo->addFile('file.txt');
$repo->addFile('file1.txt', 'file2.txt');
$repo->addFile(['file3.txt', 'file4.txt']);
// renames files in repository
$repo->renameFile('old.txt', 'new.txt');
$repo->renameFile([
    'old1.txt' => 'new1.txt',
    'old2.txt' => 'new2.txt',
]);
// removes files from repository
$repo->removeFile('file.txt');
$repo->removeFile('file1.txt', 'file2.txt');
$repo->removeFile(['file3.txt', 'file4.txt']);
// adds all changes in repository
$repo->addAllChanges();
```

Branches
--------

[](#branches)

```
// gets list of all repository branches (remotes & locals)
$repo->getBranches();
// gets list of all local branches
$repo->getLocalBranches();
// gets name of current branch
$repo->getCurrentBranchName();
// creates new branch
$repo->createBranch('new-branch');
// creates new branch and checkout
$repo->createBranch('patch-1', TRUE);
// removes branch
$repo->removeBranch('branch-name');
```

Tags
----

[](#tags)

```
// gets list of all tags in repository
$repo->getTags();
// creates new tag
$repo->createTag('v1.0.0');
$repo->createTag('v1.0.0', $options);
$repo->createTag('v1.0.0', [
	'-m' => 'message',
]);
// renames tag
$repo->renameTag('old-tag-name', 'new-tag-name');
// removes tag
$repo->removeTag('tag-name');
```

History
-------

[](#history)

This functions working by reading files in `.git/`

```
// returns last commit ID on current branch
$commitId = $repo->getLastCommitId();
$commitId->getId(); // or (string) $commitId
// returns commit data
$commit = $repo->getCommit('734713bc047d87bf7eac9674765ae793478c50d3');
$commit->getId(); // instance of CommitId
$commit->getSubject();
$commit->getBody();
$commit->getAuthorName();
$commit->getAuthorEmail();
$commit->getAuthorDate();
$commit->getCommitterName();
$commit->getCommitterEmail();
$commit->getCommitterDate();
$commit->getDate();
// returns commit data of last commit on current branch
$commit = $repo->getLastCommit();
```

Remotes
-------

[](#remotes)

```
// pulls changes from remote
$repo->pull('remote-name', ['--options']);
$repo->pull('origin');
// pushs changes to remote
$repo->push('remote-name', ['--options']);
$repo->push('origin');
$repo->push(['origin', 'master'], ['-u']);
// fetchs changes from remote
$repo->fetch('remote-name', ['--options']);
$repo->fetch('origin');
$repo->fetch(['origin', 'master']);
// adds remote repository
$repo->addRemote('remote-name', 'repository-url', ['--options']);
$repo->addRemote('origin', 'git@github.com:pvpender/git-kphp.git');
// renames remote
$repo->renameRemote('old-remote-name', 'new-remote-name');
$repo->renameRemote('origin', 'upstream');
// removes remote
$repo->removeRemote('remote-name');
$repo->removeRemote('origin');
// changes remote URL
$repo->setRemoteUrl('remote-name', 'new-repository-url');
$repo->setRemoteUrl('upstream', 'https://github.com/pvpender/git-kphp.git');
```

Based on

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~11 days

Total

4

Last Release

1219d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f0d8fbe8fbb5c6269c322f133b073cc912590bbd38f44dead4126a1441194d5d?d=identicon)[pvpender](/maintainers/pvpender)

---

Top Contributors

[![pvpender](https://avatars.githubusercontent.com/u/59583646?v=4)](https://github.com/pvpender "pvpender (43 commits)")

---

Tags

git

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/pvpender-git-kphp/health.svg)

```
[![Health](https://phpackages.com/badges/pvpender-git-kphp/health.svg)](https://phpackages.com/packages/pvpender-git-kphp)
```

###  Alternatives

[czproject/git-php

Library for work with Git repository in PHP.

5544.9M81](/packages/czproject-git-php)[cypresslab/gitelephant

An abstraction layer for git written in PHP

6131.0M23](/packages/cypresslab-gitelephant)[bruli/php-git-hooks

Git hooks for PHP projects.

675370.8k5](/packages/bruli-php-git-hooks)[marcocesarato/php-conventional-changelog

Generate changelogs and release notes from a project's commit messages and metadata and automate versioning with semver.org and conventionalcommits.org

2511.3M109](/packages/marcocesarato-php-conventional-changelog)[ramsey/conventional-commits

A PHP library for creating and validating commit messages according to the Conventional Commits specification. Includes a CaptainHook action!

1931.2M122](/packages/ramsey-conventional-commits)[sebastianfeldmann/git

PHP git wrapper

466.9M18](/packages/sebastianfeldmann-git)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
