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

无法初始化私有仓库子模块,SSH权限报错求助解决

问题诊断与解决步骤

这大概率不是GitHub的bug,是本地Git配置、SSH代理或子模块权限/URL配置的问题,可按以下步骤排查:

1. 检查并修正子模块URL配置

先确认.gitmodules文件里子模块的实际地址:

cat .gitmodules

如果content子模块的url仍是SSH格式(git@github.com:vishvAsa/rahaShTippanyaH.git),即使手动切换过上游,也可能未同步到配置文件,需修改为HTTPS格式并提交:

git config --file .gitmodules submodule.content.url https://github.com/vishvAsa/rahaShTippanyaH.git
git add .gitmodules
git commit -m "Update submodule URL to HTTPS"
git submodule sync
git submodule update --init --remote

2. 验证HTTPS凭据有效性

私有仓库用HTTPS访问需使用GitHub个人访问令牌(PAT)作为密码,先手动测试克隆子模块:

git clone https://github.com/vishvAsa/rahaShTippanyaH.git ./test-content

提示输入用户名时填GitHub账号名,密码填PAT(而非GitHub登录密码)。若克隆成功,说明是Git凭据缓存问题,可配置凭据助手自动保存:

# 临时缓存15分钟
git config --global credential.helper cache
# 或长期保存
git config --global credential.helper store

3. 排查SSH代理与密钥问题

即使ssh-add -l显示密钥,仍可能存在代理或权限异常:

  • 测试SSH连接GitHub,查看详细日志:
    ssh -vT git@github.com
    
    若输出含sign_and_send_pubkey: signing failed,执行以下操作:
    • 修正密钥文件权限(SSH要求严格权限):
      chmod 700 ~/.ssh
      chmod 600 ~/.ssh/id_rsa
      
    • 重启SSH代理并重新添加密钥:
      eval "$(ssh-agent -s)"
      ssh-add ~/.ssh/id_rsa
      
    • 确认该RSA公钥已添加到GitHub账号:登录GitHub→设置→SSH和GPG密钥,检查是否存在对应公钥。

4. 确认子模块分支配置

若content是指定要拉取的分支,需在.gitmodules里明确配置分支:

git config --file .gitmodules submodule.content.branch content
git add .gitmodules
git commit -m "Set submodule to track content branch"
git submodule sync
git submodule update --init --remote

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 22:30:53