-
v2.0 Stable
released this
2026-08-14 19:31:41 +08:00 | 2 commits to main since this releaseFull Changelog: https://github.com/hanyixuanten/php-git-server/compare/v1.0...v2.0
v2.0
中文
新增
- 新增 MySQL 账号注册、登录和管理员配置。
- 新增哈希存储、可撤销的 Git Access Token;Git 操作通过 HTTP Basic 认证。
- 新增仓库所有权、公开/私有可见性以及仅所有者可推送的权限模型。
- 新增管理页面,可管理用户、密码、Token、仓库所有权和可见性。
- 新增 Web 安装页面,用于初始化数据库、管理员账号和配置文件。
- 新增中英文界面及浏览器语言检测。
- 新增托管仓库创建、所有者删除和数据库元数据管理。
- 新增无依赖的 Git 协议回归测试套件,覆盖 clone、fetch、push、分支、标签和异常对象。
变更
- Smart HTTP 现在完全由纯 PHP 实现,不再依赖 Git 可执行文件或
proc_open。 - 改进 upload-pack 协商,支持
multi_ack_detailed、no-done、thin-pack和include-tag。 - 首次推送非
main分支时,可自动更新未出生仓库的默认HEAD。 - 托管仓库统一存储在项目的
repos目录中。 - 更新首页、安装页和管理页 UI,并扩充部署与运维文档。
修复
- 加强 commit、tree 和 annotated tag 的格式、连接性与对象类型验证。
- 修复 receive-pack 部分 ref 更新失败时的回滚行为。
- 修复 Git 协议处理失败时仍报告成功的问题。
- 修复默认分支在
main与master之间不一致的问题。 - 修复仓库目录权限和路由处理问题。
安全
- 私有仓库的 Smart HTTP 与 Dumb HTTP 读取均要求有效 Access Token。
- 推送同时验证 Access Token 身份和仓库所有权。
- Token 明文仅显示一次,数据库只保存 SHA-256 摘要。
- 私有仓库响应使用禁止共享缓存的安全缓存策略。
- 管理、认证和仓库修改操作加入 Session 与 CSRF 防护。
破坏性变更
- 删除 Git 可执行文件后端;SHA-256 仓库、浅克隆、过滤克隆、Git hooks、签名推送证书和仅 Git protocol v2 提供的功能不受支持。
- 旧版
require_auth/REMOTE_USER权限模型不再控制访问;推送需要应用账号、Access Token 和明确的仓库所有者。 - 启用账号认证需要 MySQL 5.7+ 或 MariaDB 10.2+ 以及 PHP
pdo_mysql。 - 托管仓库路径不再可配置,固定为项目下的
repos目录。
完整变更:v1.0...v2.0
English
Added
- Added MySQL-backed account registration, login, and administrator configuration.
- Added hashed, revocable Git access tokens with HTTP Basic authentication.
- Added repository ownership, public/private visibility, and owner-only pushes.
- Added an administration page for managing users, passwords, tokens, ownership, and visibility.
- Added a web installer for initializing the database, administrator account, and configuration.
- Added English and Chinese interfaces with browser language detection.
- Added managed-repository creation, owner deletion, and database-backed metadata.
- Added a dependency-free Git protocol regression suite covering clone, fetch, push, branches, tags, and malformed objects.
Changed
- Smart HTTP is now implemented entirely in PHP and no longer depends on the Git executable or
proc_open. - Improved upload-pack negotiation with
multi_ack_detailed,no-done,thin-pack, andinclude-tag. - The default
HEADof an unborn repository can now follow the first pushed branch when it is notmain. - Managed repositories are now stored in the project's
reposdirectory. - Updated the home, installation, and administration interfaces and expanded deployment documentation.
Fixed
- Strengthened commit, tree, and annotated-tag format, connectivity, and object-type validation.
- Fixed rollback when part of a receive-pack ref update fails.
- Fixed Git protocol failures being reported as successful operations.
- Fixed inconsistent
mainandmasterdefault-branch handling. - Fixed repository-directory permissions and routing behavior.
Security
- Private Smart HTTP and Dumb HTTP reads now require a valid access token.
- Pushes verify both the access-token identity and repository ownership.
- Token plaintext is displayed only once; only its SHA-256 digest is stored.
- Private repository responses use cache controls that prevent shared caching.
- Added session and CSRF protections to administration, authentication, and repository mutations.
Breaking Changes
- Removed the Git executable backend; SHA-256 repositories, shallow or filtered clones, Git hooks, signed push certificates, and protocol-v2-only features are unsupported.
- The former
require_auth/REMOTE_USERauthorization model no longer controls access; pushes require an application account, access token, and explicit repository owner. - Enabling account authentication requires MySQL 5.7+ or MariaDB 10.2+ and PHP
pdo_mysql. - The managed-repository path is no longer configurable and is fixed to the project's
reposdirectory.
Full Changelog: v1.0...v2.0
Downloads
-
v1.0 Stable
released this
2026-08-09 19:09:18 +08:00 | 16 commits to main since this releaseFull Changelog: https://github.com/hanyixuanten/git-server-php/commits/v1.0
PHP Git Server v1.0.0
一个可在服务器无法执行
git命令时,使用纯 PHP 提供 Git Smart HTTP 与 Dumb HTTP 服务的轻量级 Git 服务器。A lightweight Git server that provides Smart HTTP and Dumb HTTP services through pure PHP when the server cannot execute the
gitcommand.
中文
核心功能
- 支持通过 HTTP 发布显式配置的 bare Git 仓库。
- 支持
clone、fetch、pull和push。 - 支持远程分支和标签的创建、更新与删除。
- Git CLI 可用时,使用标准
git-upload-pack和git-receive-pack。 - Git CLI 或
proc_open不可用时,自动切换到纯 PHP Git 协议后端。 - 无 Composer 依赖,最低支持 PHP 7.4。
纯 PHP Smart HTTP
原生 PHP 后端实现了 Git Smart HTTP 的主要服务端能力:
GET /info/refs?service=git-upload-packPOST /git-upload-packGET /info/refs?service=git-receive-packPOST /git-receive-pack- pkt-line 编码、解码和特殊数据包处理。
- Git protocol v0/v1 风格的 refs 与 capabilities 广告。
want、have、ACK和NAK协商。side-band-64k数据传输。- SHA-1 loose object 读取、写入和哈希校验。
- pack index v2 读取。
- pack v2 解析与生成。
- OFS_DELTA 和 REF_DELTA 展开。
- commit、tree、blob、annotated tag 对象处理。
- commit、tree 和 tag 可达性遍历。
- 限制客户端只能请求已发布 refs 可达的对象。
原生 Push
- 支持首次向空仓库 push。
- 支持分支和标签的创建、更新与删除。
- 校验 pack SHA-1 checksum 和对象 ID。
- 校验提交、目录、文件和标签之间的对象连通性。
- 分支 ref 只能指向 commit 对象。
- 默认拒绝 non-fast-forward 分支更新。
- 可通过
allow_non_fast_forward显式允许强制更新。 - 使用 ref
.lock文件和 old OID 比较避免并发覆盖。 - 支持 loose refs 与
packed-refs。 - 拒绝重复 ref 命令和 ref 文件/目录命名空间冲突。
- 支持
report-status、delete-refs、side-band-64k和ofs-delta。 - 支持按仓库限制请求大小、对象大小和 pack 对象数量。
Dumb HTTP
保留完整的只读 Dumb HTTP 兼容路径:
HEADinfo/refsobjects/info/packsobjects/info/alternatesobjects/info/http-alternates- loose objects
- pack 文件
- pack index
- loose refs
- packed refs
- annotated tag peeled refs
仓库管理
- 首页列出允许读取的仓库。
- 显示 clone URL、默认分支、分支数量、标签数量和 push 权限。
- 支持从首页创建 bare 仓库。
- Git 不可用时通过纯 PHP 初始化标准 SHA-1 bare 仓库。
- 新仓库默认分支为
main。 - 使用 CSRF token 保护仓库创建表单。
- 使用创建锁、临时目录和原子重命名避免并发覆盖。
- 自动发现受控目录下的
.git仓库。 - 静态仓库配置优先于自动发现的仓库。
权限与安全
每个仓库可以独立配置:
readpushrequire_authbranchestagsother_refsallow_non_fast_forwardmax_request_bytesmax_object_bytesmax_pack_objects
其他安全措施:
- push 默认关闭。
- 可要求 Web 服务器提供可信的
REMOTE_USER。 - 仓库路径经过
realpath()和目录边界检查。 - 不根据 URL 拼接任意文件系统路径。
- 拒绝非法 ref 名称和目录穿越。
- 支持 push 请求落盘和大小限制。
- immutable Git 对象使用长期 HTTP 缓存。
- refs 和协议响应使用 no-cache。
- 设置
X-Content-Type-Options: nosniff。 - 首页使用 Content Security Policy。
- 验证 Host header 后才生成绝对 clone URL。
- 支持安全会话 Cookie、HttpOnly、SameSite 和 HTTPS Secure 属性。
原生后端限制
以下功能当前需要服务器安装 Git:
- SHA-256 仓库的完整 Smart HTTP 支持。
- Git protocol v2 专属命令。
- shallow clone 和 shallow fetch。
- partial clone 与 object filter。
- push certificate 和签名验证。
- Git hooks。
- Git maintenance、repack 和 garbage collection。
原生 PHP 多 ref push 会先锁定并校验所有 refs,但最终 ref 文件仍逐项提交,不提供文件系统级事务回滚。
English
Core Features
- Publishes explicitly configured bare Git repositories over HTTP.
- Supports
clone,fetch,pull, andpush. - Supports remote branch and tag creation, updates, and deletion.
- Uses standard
git-upload-packandgit-receive-packwhen Git CLI is available. - Automatically switches to the native PHP backend when Git CLI or
proc_openis unavailable. - Requires no Composer dependencies and supports PHP 7.4 or newer.
Native PHP Smart HTTP
The native backend implements the primary Git Smart HTTP server operations:
GET /info/refs?service=git-upload-packPOST /git-upload-packGET /info/refs?service=git-receive-packPOST /git-receive-pack- pkt-line encoding, decoding, and special packet handling.
- Protocol v0/v1-style ref and capability advertisements.
want,have,ACK, andNAKnegotiation.side-band-64ktransport.- SHA-1 loose object reading, writing, and hash validation.
- Pack index v2 reading.
- Pack v2 parsing and generation.
- OFS_DELTA and REF_DELTA resolution.
- Commit, tree, blob, and annotated tag handling.
- Commit, tree, and tag reachability traversal.
- Restricts wants to objects reachable from advertised refs.
Native Push
- Supports the first push to an empty repository.
- Supports branch and tag creation, updates, and deletion.
- Validates pack SHA-1 checksums and object IDs.
- Validates object graph connectivity.
- Requires branch refs to point to commit objects.
- Rejects non-fast-forward branch updates by default.
- Forced branch rewrites can be enabled with
allow_non_fast_forward. - Uses ref lock files and old-OID comparisons to prevent concurrent overwrites.
- Supports loose refs and
packed-refs. - Rejects duplicate ref commands and file/directory namespace conflicts.
- Supports
report-status,delete-refs,side-band-64k, andofs-delta. - Provides per-repository request, object-size, and pack-object limits.
Dumb HTTP
A complete read-only Dumb HTTP compatibility path remains available:
HEADinfo/refsobjects/info/packsobjects/info/alternatesobjects/info/http-alternates- Loose objects
- Pack files
- Pack indexes
- Loose refs
- Packed refs
- Peeled annotated tag refs
Repository Management
- Lists readable repositories on the home page.
- Displays clone URLs, default branches, branch and tag counts, and push access.
- Creates bare repositories from the home page.
- Initializes standard SHA-1 bare repositories through pure PHP when Git is unavailable.
- Uses
mainas the default branch. - Protects repository creation with CSRF tokens.
- Uses creation locks, temporary directories, and atomic renames.
- Automatically discovers
.gitrepositories in a managed directory. - Gives static repository definitions precedence over discovered repositories.
Access Control and Security
Each repository can configure:
readpushrequire_authbranchestagsother_refsallow_non_fast_forwardmax_request_bytesmax_object_bytesmax_pack_objects
Additional protections include:
- Push is disabled by default.
- Authentication can require a trusted web-server
REMOTE_USER. - Repository paths are protected with
realpath()containment checks. - Filesystem paths are never constructed directly from arbitrary URLs.
- Invalid refs and path traversal are rejected.
- Push requests can be spooled and size-limited.
- Immutable Git objects receive long-lived HTTP caching.
- Ref and protocol responses use no-cache headers.
- Responses use
X-Content-Type-Options: nosniff. - The home page uses Content Security Policy.
- Absolute clone URLs are generated only after Host header validation.
- Session cookies support HttpOnly, SameSite, and HTTPS Secure attributes.
Native Backend Limitations
The following features currently require an installed Git executable:
- Complete Smart HTTP support for SHA-256 repositories.
- Protocol v2-only commands.
- Shallow clone and shallow fetch.
- Partial clone and object filters.
- Push certificates and signature verification.
- Git hooks.
- Git maintenance, repacking, and garbage collection.
Native multi-ref pushes lock and validate all refs before committing, but final ref files are still committed individually and do not provide filesystem-level transactional rollback.
Downloads