已配置SSH Key仍执行pub get失败的Git仓库访问问题
解决pub get时Git仓库找不到的问题
问题说明
在IntelliJ IDE克隆项目后首次执行pub get,触发Git错误,具体命令及报错信息如下:
Git error. Command: `git clone --mirror git@github.com:open-runtime/aot_monorepo.git /Users/tarun/.pub-cache/git/cache/aot_monorepo-7a0b3d0f0477d2766d0540e8a0101f937bb7f0bf` stdout: stderr: Cloning into bare repository '/Users/tarun/.pub-cache/git/cache/aot_monorepo-7a0b3d0f0477d2766d0540e8a0101f937bb7f0bf'... ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. exit code: 128
已通过ssh -T git@github.com确认SSH身份验证正常,同一组织下其他仓库曾通过验证SSH Key解决类似问题,但本次另一仓库仍触发该错误。
排查与解决步骤
1. 手动验证仓库访问权限
在终端直接执行克隆命令,确认是否能正常拉取:
git clone --mirror git@github.com:open-runtime/aot_monorepo.git
如果同样报错,联系组织仓库管理员确认:
- 仓库
open-runtime/aot_monorepo是否存在(未被删除或重命名) - 你的GitHub账号是否被授予该仓库的读取权限
2. 检查SSH配置冲突
查看~/.ssh/config文件,确认是否存在针对github.com的配置冲突(比如指定了错误的密钥文件):
cat ~/.ssh/config
若存在多GitHub账号配置,可添加针对该组织的专属配置:
Host github.com-open-runtime HostName github.com User git IdentityFile ~/.ssh/你的组织专用密钥文件名
之后将项目依赖中的仓库地址替换为github.com-open-runtime:open-runtime/aot_monorepo.git,或直接修改pubspec.yaml中的依赖源。
3. 清除Pub缓存后重试
删除Pub缓存中对应仓库的缓存目录:
rm -rf /Users/tarun/.pub-cache/git/cache/aot_monorepo-7a0b3d0f0477d2766d0540e8a0101f937bb7f0bf
重新执行pub get,或在IntelliJ中点击"Pub Get"按钮。
4. 统一IntelliJ与终端的Git环境
确认IntelliJ使用的Git路径和终端一致:
- 打开IntelliJ的
Preferences(Mac系统) - 导航到
Version Control > Git - 检查
Path to Git executable是否与终端执行which git的输出一致
若路径不同,修改为终端使用的Git路径,重启IntelliJ后重试。
5. 确认SSH密钥的组织权限
登录GitHub账号,进入Settings > SSH and GPG keys:
- 确认当前使用的SSH密钥已获得
open-runtime组织的访问权限 - 若为个人密钥,需联系组织管理员将你加入对应团队或直接授予仓库权限
内容的提问来源于stack exchange,提问作者Tarun Kumar S
相关产品推荐
相关产品推荐

