Skip to content

用 HTTPS 推 GitHub 时,有时不是账号错,而是 Git 找不到 CA 证书文件:

text
fatal: unable to access 'https://github.com/<user>/<repo>.git/':
error setting certificate verify locations:
CAfile: C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
CApath: none

报错里的路径,是 Git 以为证书在的地方。安装目录迁过、便携版、或者 http.sslcainfo 指到了已经不存在的盘,就会这样。

不要用 git config --global http.sslverify false 当常规解法。那是关掉校验,中间人可以冒充远端。

先看本机 Git 真正的证书文件在哪。Git Bash 里常见于安装目录下的 mingw64/ssl/certs/ca-bundle.crt。确认文件在,再指过去:

bash
git config --global --get http.sslcainfo
git config --global http.sslcainfo "C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt"

路径按你机器上的实际位置改,以报错里那一行为线索。能用 --global 就不要用 --system,少动全机配置。

公司代理要额外塞企业 CA 时,把那份 CA 追加进 bundle,或单独设 http.sslCAInfo 指向合并后的文件,而不是关校验。能走 SSH 的仓库,也可以改成 SSH,绕开这一层 HTTPS 证书路径。

测试开发工程师 · 专注自动化与系统架构 | 邮箱: hansblog@atumsoul.win