SkillAgentSearch skills...

Phpgit

πŸ›  Git wrapper and feature extension library written in PHP.

Install / Use

/learn @phppkg/Phpgit
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

PhpGit

GitHub tag (latest SemVer) Php Version Support Unit Tests Deploy Pages

δΈ­ζ–‡θ―΄ζ˜Ž

PhpGit - πŸ’ͺ Git wrapper and feature extension library written in PHP.

The project is forked from https://github.com/kzykhys/PHPGit

Features

  • Quick run git commands, eg: clone,add,commit,merge
  • Git repo info fetch: status branch remote
  • Generate changelog by git log

Installation

Requirements

  • PHP 8.1+
  • Git

Method 1: directly composer require

composer require phppkg/phpgit

Method 2: update composer.json

Update your composer.json and run composer update

{
    "require": {
        "phppkg/phpgit": "dev-master"
    }
}

Basic Usage

<?php

require __DIR__ . '/vendor/autoload.php';

$git = PhpGit\Git::new();
$git->clone('https://github.com/phppkg/PhpGit.git', '/path/to/repo');
$git->setRepository('/path/to/repo');
$git->remote->add('production', 'git://example.com/your/repo.git');

$git->add('README.md');
$git->commit('Adds README.md');

$git->checkout('release');
$git->merge('master');

$git->push();
$git->push('production', 'release');

$git->tag->create('v1.0.1', 'release');

foreach ($git->tree('release') as $object) {
    if ($object['type'] == 'blob') {
        echo $git->show($object['file']);
    }
}

Git Info

$repo = PhpGit\Repo::new('/path/to/repo');

$remotes = $repo->getRemotes();

$url  = $repo->getRemoteUrl('origin');
$info = $repo->getRemoteInfo('origin');

var_dump($info);

Output:

object(PhpGit\Info\RemoteInfo)#35 (8) {
  ["type"]=> string(4) "http"
  ["name"]=> string(6) "origin"
  ["url"]=> string(34) "https://github.com/phppkg/phpgit.git"
  ["scheme"]=> string(5) "https"
  ["host"]=> string(10) "github.com"
  ["path"]=> string(11) "phppkg/phpgit"
  ["group"]=> string(4) "ulue"
  ["repo"]=> string(6) "phpgit"
}

Changelog

Provide quick generate formatted changelog.

Formatter

  • SimpleFormatter
  • MarkdownFormatter
  • GithubReleaseFormatter

Filter

  • KeywordFilter
  • KeywordsFilter
  • MsgLenFilter
  • WordsLenFilter

Example

use Toolkit\Cli\Color;
use PhpGit\Changelog\Formatter\GithubReleaseFormatter;
use PhpGit\Changelog\Formatter\SimpleFormatter;
use PhpGit\Changelog\GitChangeLog;

// this is built in log format.
// you can custom format string, but must be set an log parser by $gcl->setLineParser(new YourLineParser);
$logFormat = GitChangeLog::LOG_FMT_HSC;

$oldVersion = 'v0.2.1';
$newVersion = 'HEAD';

// get output by git log cmd:
//  `git log v0.2.1...HEAD --reverse --pretty=format:"%H | %s | %cn" --no-merges`
$c = PhpGit\Git::new()->newCmd('log');
$c->add("$oldVersion...$newVersion");
$c->add('--reverse');
$c->addf('--pretty=format:"%s"', $logFormat);

// get repo url
$info = PhpGit\Repo::new()->getRemoteInfo('origin');
$repoUrl = $info->getHttpUrl();
Color::info('repo URL: ' . $repoUrl);

// create object by output.
$gcl = GitChangeLog::new($c->getOutput());
$gcl->setLogFormat($logFormat);
$gcl->setRepoUrl($repoUrl);

// you can set output style. default is markdown.
// can also, you can custom your item formatter
$gcl->setItemFormatter(new GithubReleaseFormatter());
//$gcl->setItemFormatter(new SimpleFormatter());

Color::info('parse logs and generate changelog');

// parse and generate.
$str = $gcl->generate();

echo $str;

Run example php bin/chlog.php will see:

> git log v0.2.1...HEAD --reverse --pretty=format:"%H | %s | %cn" --no-merges
> git remote -v
[INFO] repo URL:https://github.com/phppkg/phpgit
[INFO] parse logs and generate changelog

### Fixed

 - fix get latest tag error on windows https://github.com/phppkg/phpgit/commit/b9892b0ec363e405fcb76b08ea971fb651b4d2dc

### Update

 - up: rename package org to phppkg https://github.com/phppkg/phpgit/commit/990e55c6beddf654819c323c2a18d329074399f9
 - update some info https://github.com/phppkg/phpgit/commit/"1110de8b5ef0406c837bcd65f607b6f9483c9154

### Feature

 - feat: add util for quick generate change log https://github.com/phppkg/phpgit/commit/50962c12d3f16cdbbd8c1f21bc17ff920842365e

API

Git commands

Related Skills

View on GitHub
GitHub Stars13
CategoryDevelopment
Updated4d ago
Forks4

Languages

PHP

Security Score

95/100

Audited on Mar 31, 2026

No findings