github-protocols仅影响github.com域名下的仓库克隆协议顺序,按数组顺序尝试并自动fallback;default-protocol全局控制未显式指定协议的vcs地址;insteadof在git层重写url最底层可靠;secure-http只校验元数据和dist包https,不限制git clone协议。

github-protocols 配置只影响 GitHub 仓库的克隆顺序
这个配置项不控制所有 Git 仓库,只对 github.com 域名下的包生效。Composer 会按你写的数组顺序依次尝试协议,比如 ["ssh","https"] 表示先走 git@github.com:user/repo.git,失败再试 https://github.com/user/repo.git。
常见错误现象:设了 ["ssh"] 却还是走 HTTPS —— 这不是配置没生效,而是 SSH 尝试失败后自动 fallback 到默认行为(Composer 内部兜底逻辑),你根本不会看到报错。
- 必须确保
ssh -T git@github.com能通,且~/.ssh/config里有对应 Host 段 - 如果项目
composer.json的repositories里硬写了https://github.com/...,这个 URL 会直接跳过github-protocols判断 - 执行
composer update -vvv,搜日志里的Cloning行,才能确认实际走的是哪个协议
全局 default-protocol 才真正统一非 GitHub 仓库的协议
composer config -g default-protocol https 是更通用的方案,它作用于所有未显式带协议的 VCS 地址,比如 gitlab.com、gitee.com、甚至公司自建 Git 服务器。Composer 会把 vendor/package 这类简写自动补成 https://gitlab.com/vendor/package.git。
注意它不覆盖已写死的协议:如果你在 repositories 里写了 "url": "git@gitlab.com:org/repo.git",那这条配置就完全绕过 default-protocol。
围绕关键发现、作用机制、临床相关性及研究局限性展开讨论。适用于撰写或优化任何生物医学论文的“讨论(Discussion)”部分——包括结果解读、与既往文献关联、阐释意外发现、界定研究局限性,以及撰写结论。当用户输入以下任一指令时也会自动触发该功能: - “write my discussion” - “help me discuss my findings” - “how do I compare to prior studies” - “write the limitations par
- 可选值是
https、ssh、git、http,但http在secure-http=true下会被直接拒绝 - 私有 Git 服务若只支持 SSH,就得配
ssh,同时确保所有机器的~/.ssh/id_rsa和~/.ssh/config一致 - 这个配置对 submodule 无效——submodule 的协议由其自身
.gitmodules决定,Composer 不干预
Git 层 insteadOf 重写比 Composer 配置更底层、更可靠
当你要让所有 HTTPS 地址(包括硬编码的)都走 SSH,或者反过来,git config --global url."git@github.com:".insteadOf "https://github.com/" 是唯一能穿透所有层的方案。它发生在 Git 执行 clone 前一刻,Composer 完全感知不到。
这招特别适合 CI 环境:镜像里预装好 SSH key,再配好 insteadOf,哪怕 composer.json 里全是 HTTPS 地址,实际拉取时也全变成 SSH。
- 对 GitLab 同理:
git config --global url."git@gitlab.com:".insteadOf "https://gitlab.com/" - 如果 SSH 配置不全(比如
ForwardAgent no或没设Host gitlab.com),composer install会在 clone 阶段卡住,报Permission denied (publickey) - 该配置不依赖 Composer 版本,也不受
secure-http影响——因为协议判断在 Composer 层,重写在 Git 层
secure-http 是 HTTPS 强制的最终防线,但管不了 Git 克隆
composer config -g secure-http true 只校验仓库元数据(如 packages.json)和 dist 包下载地址是否为 HTTPS,它不管 git clone 用什么协议。也就是说,即使 secure-http 开着,github-protocols 仍可能让 Composer 走 SSH 克隆。
容易被忽略的一点:如果你的私有 Git 仓库只提供 HTTPS 接入,但证书是自签名的,secure-http 不会报错,但 git clone 会因 SSL 验证失败而中断——这时得额外配 git config --global http.sslVerify false(不推荐)或 composer config --global cafile /path/to/cert.pem。
- 这个设置对 Packagist 官方源是硬编码生效的,改
repo.packagist.org配置无效 - 如果某次
composer update报错The 'http://' URL 'http://xxx' is not allowed,说明secure-http正常工作了 - 它不修正已缓存的 HTTP 包,只约束后续请求;已下载的
vendor/不受影响










