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

git fetch正常但git fetch --all出现公钥权限错误,如何解决?

问题根源

你的问题出在main远程仓库的地址配置错误:

  • main远程的fetch地址是ssh://git/core/main.git,这个格式缺少GitLab服务器的主机名(比如git.mycompany.com),导致Git尝试用当前系统用户myfirstname.mylastname去连接一个名为git的不存在主机,直接触发公钥权限拒绝。
  • 单独执行git fetch时,Git默认只拉取origin远程(克隆时默认创建的远程),所以不会碰main远程的错误配置,因此能成功。
解决方法

方法1:修正main远程的地址

执行命令把main远程的地址改成和origin一致的正确地址:

git remote set-url main git@git.mycompany.com:core/main.git

或者用完整SSH路径格式:

git remote set-url main ssh://git@git.mycompany.com/core/main.git

方法2:删除多余的main远程

如果main远程和origin指向同一个仓库,完全可以直接删掉它:

git remote remove main
验证操作

执行git remote -v确认配置修改/删除成功,再运行git fetch --all测试,此时应该能正常拉取所有远程更新。

内容的提问来源于stack exchange,提问作者Mayor of the Plattenbaus

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.16 00:16:09