| name | cli-git-mirror |
| description | Use when: 开发 git 镜像端点自动代理——clone/pull/push 转发、info/refs、upload-pack/receive-pack、insteadOf 配置。 |
| argument-hint | 需要实现/调试哪个 CLI 代理端点或协议细节 |
CLI git 镜像端点自动代理
Worker 职责之一:将 git CLI 流量自动代理转发到 GitHub。用户通过 insteadOf 接入,无需安装额外客户端。
用户接入
git config --global url.https://<worker域名>/.insteadOf https://github.com/
git 智能 HTTP 协议
| 请求 | 说明 |
|---|
GET /<owner>/<repo>.git/info/refs?service=git-upload-pack | fetch/clone 第一步 |
GET /<owner>/<repo>.git/info/refs?service=git-receive-pack | push 第一步 |
POST /<owner>/<repo>.git/git-upload-pack | fetch 数据 |
POST /<owner>/<repo>.git/git-receive-pack | push 数据 |
转发要点
- 路径重写:替换 host 为
github.com,转发 https://github.com<path>
- header 透传:Content-Type / Accept / User-Agent 按 git 协议要求;移除 Host / Content-Length 由 fetch 重算
- 响应透传:保留 Content-Type / Content-Length 或 chunked
- POST 体原样转发(
request.body 直通)
- 错误处理:404/403 透传 GitHub 状态码与 body
鉴权(push)
- git 凭据使用 PAT(URL 内嵌或 git credential)
- Worker 将
Authorization: Basic <user:PAT> 透传给 GitHub;只读公开仓库无需凭据