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

如何将linux/rpi-linux内核镜像同步到私有git仓库并解决推送报错

内核仓库同步SSH断开问题解决方案

问题根因

Linux内核类超大仓库(体积通常在5GB以上)全量镜像推送时,默认Git、SSH配置的传输缓冲区过小、连接超时阈值过低,会触发远程服务器主动断开SSH连接,对应你收到的报错提示。

具体修复步骤

第一步:调整SSH配置适配大文件传输

编辑本地SSH配置文件~/.ssh/config,添加以下参数:

Host github.com
  ServerAliveInterval 60
  ServerAliveCountMax 10
  Compression yes
  TCPKeepAlive yes
  # 如果走本地代理可额外添加以下配置,端口替换为你实际的代理端口
  # ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p

第二步:调整Git全局传输配置

执行以下命令修改Git参数,适配大体积仓库的打包传输:

git config --global pack.windowMemory "1024m"
git config --global pack.packSizeLimit "1024m"
git config --global pack.threads "4"
git config --global core.compression 9
git config --global ssh.postBuffer 1048576000

第三步:分批推送避免一次性传输过载

不要直接执行全量git push --mirror,先分批推送核心内容降低单次传输压力:

  1. 进入你克隆的裸仓目录,先推送主分支:
    git push git@example.com/new-location.git master
  2. 推送其余开发分支:
    git push git@example.com/new-location.git --all
  3. 推送所有标签:
    git push git@example.com/new-location.git --tags
  4. 所有内容推送完成后,最后执行一次mirror命令补全遗漏的引用:
    git push --mirror git@example.com/new-location.git

可选替代方案

如果SSH协议始终无法推送成功,可临时切换为HTTPS协议推送:

  1. 修改私有仓库远程地址为HTTPS格式:
    git remote set-url --push origin https://github.com/你的用户名/你的私有仓库.git
  2. 配置Git凭据缓存避免重复输入密码:
    git config --global credential.helper store
  3. 再执行上述分批推送操作即可。

后续自动同步配置

要实现上游内核更新时自动同步到私有仓库,可编写定时执行脚本:

#!/bin/bash
# 进入本地裸仓目录
cd /path/to/your/upstream-repository.git
# 拉取上游最新改动
git remote update
# 同步到私有仓库
git push --mirror git@example.com/new-location.git

将脚本加入系统定时任务(如Linux crontab),设置对应执行周期即可。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.16 07:06:07