Git克隆卡在“Cloning into”是Git层超时,非Composer或Jenkins配置问题;需先手动运行git clone复现,再分HTTPS/SSH协议排查网络、认证、代理及SSL配置。

Git克隆卡在 Cloning into 阶段,不是 Composer 或 Jenkins 配置问题,而是 Git 自身的网络连接/认证环节失败——改 process-timeout、换镜像源、调 Jenkins 超时参数,全都不起作用。
先手动复现,确认是 Git 层卡死
Composer、Jenkins、IDEA 等工具调用的是系统 git 命令,它们本身不处理克隆逻辑。所以第一步必须脱离上层工具,直接跑原生命令:
- 运行
git clone https://github.com/your-org/repo.git /tmp/test-clone(HTTPS 场景) - 或
git clone git@github.com:your-org/repo.git /tmp/test-clone(SSH 场景) - 观察是否同样卡住、卡在哪一步(如卡在
Resolving deltas是本地解包问题;卡在开头几秒没反应,大概率是连接或认证失败)
只有能手动复现,后续排查才有意义。不能复现?那问题在上层工具的封装逻辑里(比如 IDEA 用了内置 Git、Jenkins 没传对凭据)。
HTTPS 克隆失败:检查 Token、代理、SSL 三件套
企业网或 CI 环境下 HTTPS 克隆失败,90% 出在这三个地方:
-
403 Forbidden:GitHub/GitLab 启用 2FA 后,密码失效,必须用 Personal Access Token 替代。配置方式:composer config --global github-oauth.github.com(Composer 场景),或 URL 中嵌入:https://@github.com/owner/repo.git - 走代理但 Git 没配:
git不读http_proxy环境变量,必须显式设:git config --global http.proxy http://proxy.example.com:8080;HTTPS 仓库还要额外设:git config --global https.proxy http://proxy.example.com:8080 -
SSL certificate problem或unable to get local issuer certificate:不是证书过期,是 Git 没读系统 CA 证书路径。Linux 下执行git config --global http.sslCAInfo "/etc/ssl/certs/ca-certificates.crt";Windows 下可指向curl-ca-bundle.crt文件。别用git config --global http.sslVerify false—— 这只是掩盖问题,且不解决私有 GitLab 自签名证书场景
SSH 克隆卡住:验证连接、保活、路径权限
SSH 方式看似简单,但实际更易因底层配置失配而静默失败:
- 先测连通性:
ssh -T git@github.com或ssh -T git@gitlab.example.com。如果超时或报Permission denied (publickey),说明密钥没加载或没上传到平台 - 内网 GitLab 常见卡在
git@xxx:xxx/yyy.git路径不对:SSH 默认用户是git,但服务器端仓库路径可能不在/home/git下,而是由 GitLab 服务管理。务必用平台提供的完整 SSH URL(如git@gitlab.example.com:group/project.git),不要自己拼 - 克隆大仓库到 7% 卡住:本质是 SSH 连接被防火墙或远端服务因低速传输中断。需在
~/.ssh/config中强制启用保活:Host gitlab.example.com User git ServerAliveInterval 10 ServerAliveCountMax 20 TCPKeepAlive yes
,并确保文件权限为600
大仓库克隆慢/中断:禁用压缩 + 浅克隆 + 分步推
超过 1GB 的仓库,完整克隆极易因网络抖动失败,不建议硬扛:
- 关压缩减远端压力:
git config --global core.compression -1 - CI/构建场景用浅克隆:
git clone --depth 1 https://...;Jenkins 流水线中通过CloneOption设depth: 1和shallow: true - 导入到 CodeArts Repo 等平台失败时,别直连拉:先
git clone --bare到本地,再git push --mirror推过去。这样规避了平台侧的单次连接超时限制
真正难的不是“怎么加 timeout”,而是判断哪一层在超时——Git 自己、SSH 守护进程、中间防火墙、远端 Git 服务,每一层的超时机制和配置位置都不同。手动复现 + 分协议验证,是唯一靠谱的起点。











