You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Linux下向GitHub推送代码时遇fatal协议错误如何解决?

解决Linux环境下Git推送到GitHub时的「fatal: protocol error: bad line length 173」错误

推送代码到GitHub时出现如下错误:

fatal: protocol error: bad line length 173

完整操作日志:

$ git push --set-upstream origin main
Username for 'https://github.com': user
Password for 'https://user@github.com': 
fatal: protocol error: bad line length 173
send-pack: unexpected disconnect while reading sideband packet
error: failed to push some refs to 'https://github.com/user/repository.git'
Enumerating objects: 32, done.
Counting objects: 100% (32/32), done.
Delta compression using up to 16 threads
Compressing objects: 100% (23/23), done.

针对GitHub场景,Linux环境下可尝试以下解决方法:

  • 切换为SSH协议推送
    HTTPS协议易触发此类协议错误,优先切换为SSH方式:

    1. 查看当前远程仓库地址:
      git remote -v
      
    2. 移除原HTTPS远程地址,添加SSH地址:
      git remote remove origin
      git remote add origin git@github.com:user/repository.git
      
    3. 确保本地已生成SSH密钥并添加至GitHub账户,之后重新执行推送:
      git push --set-upstream origin main
      
  • 清理Git凭证缓存
    若坚持使用HTTPS协议,清理本地缓存的无效凭证:

    git credential-cache exit
    

    注意:GitHub已不再支持密码登录,重新推送时需使用**个人访问令牌(PAT)**作为密码输入。

  • 增大Git HTTP缓冲区
    调整HTTP推送缓冲区大小,避免因大文件或网络波动导致中断:

    git config --global http.postBuffer 524288000
    
  • 排查网络环境
    关闭VPN、代理工具,或检查防火墙规则是否拦截Git请求;可通过以下命令验证网络连通性:

    ping github.com
    

内容的提问来源于stack exchange,提问作者mltm

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.22 00:45:02