Phpgit
π Git wrapper and feature extension library written in PHP.
Install / Use
/learn @phppkg/PhpgitREADME
PhpGit
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:
statusbranchremote - 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
SimpleFormatterMarkdownFormatterGithubReleaseFormatter
Filter
KeywordFilterKeywordsFilterMsgLenFilterWordsLenFilter
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
- PhpGit
- Installation
- Basic Usage
- Git Info
- Changelog
- API
- Git commands
- git add
- git archive
- git branch
- git cat-file
- git checkout
- git clone
- git commit
- git config
- git describe
- git fetch
- git init
- git log
- git merge
- git mv
- git pull
- git push
- git rebase
- [$git->rebase(string $upstream = null, string $branch = null, array $options = [])](#git-rebasestring-upstream--null-string-branch--null-a
Related Skills
apple-reminders
347.6kManage Apple Reminders via remindctl CLI (list, add, edit, complete, delete). Supports lists, date filters, and JSON/plain output.
gh-issues
347.6kFetch GitHub issues, spawn sub-agents to implement fixes and open PRs, then monitor and address PR review comments. Usage: /gh-issues [owner/repo] [--label bug] [--limit 5] [--milestone v1.0] [--assignee @me] [--fork user/repo] [--watch] [--interval 5] [--reviews-only] [--cron] [--dry-run] [--model glm-5] [--notify-channel -1002381931352]
healthcheck
347.6kHost security hardening and risk-tolerance configuration for OpenClaw deployments
node-connect
347.6kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
