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

GitHub Codespaces执行git submodule update --init提示publickey权限错误如何解决

GitHub Codespaces git submodule publickey 错误处理方案

错误原因

执行git submodule update --init时出现如下报错:

Warning: Permanently added 'github.com,xxxxx' (ECDSA) to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

该错误本质是Codespaces运行环境持有的身份凭证没有子模块对应仓库的访问权限,子模块的SSH拉取地址默认无法继承主仓库的Codespaces访问授权。

修复步骤

  • 方案一(长期有效,无需修改仓库配置):
    进入GitHub账号的Codespaces设置页,找到「访问权限和安全」板块,开启主仓库所属账号/组织的仓库访问授权,也可以单独添加子模块对应的仓库到授权列表,重启Codespaces后再次执行拉取命令即可。
  • 方案二(修改仓库配置,适配所有Codespaces环境):
    执行如下命令将所有子模块的SSH拉取地址替换为HTTPS协议:
    git config --file .gitmodules --get-regexp 'submodule\..*\.url' | while read sub url; do git config --file .gitmodules $sub ${url/git@github.com:/https://github.com/}; done
    
    执行完成后同步子模块配置:
    git submodule sync
    再重新执行git submodule update --init即可完成拉取。
  • 方案三(临时适用):
    将你本地有权限访问子模块仓库的SSH私钥复制到Codespaces环境中,执行ssh-add 私钥文件路径导入凭证后再拉取子模块,该方式存在私钥泄露风险,仅推荐临时测试使用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.24 12:39:01