github克隆项目中的子模块submodule时遇到“无法访问远程仓库,请检查权限“

问题描述

在拉取仓库的时候发现了新东西。

仓库中有两个文件夹提示@

点击之后,发现跳转到了另一个仓库 ,原来这是仓库的子模块,第一次见,也就是仓库中包含了其他的的仓库,就是这么简单的原理。

但是在拉取仓库以后发现这两个子模块下是空的。

原来拉去子模块要使用git clone --recursive

要是使用图形化工具,小乌龟之类的,拉取的时候记得勾上recursive

但是这还没完。包含子模块一起拉取的时候又报了错。

复制代码
git.exe clone --progress --recursive -v "https://gitee.com/hair-monk/mysql_tpcc_2024.git" "C:\Users\ybac2\Desktop\mysql_tpcc\mysql_tpcc_2024"
Cloning into 'C:\Users\ybac2\Desktop\mysql_tpcc\mysql_tpcc_2024'...
POST git-upload-pack (185 bytes)
POST git-upload-pack (212 bytes)
remote: Enumerating objects: 37, done.
remote: Counting objects: 100% (37/37), done.
remote: Compressing objects: 100% (26/26), done.
remote: Total 37 (delta 8), reused 36 (delta 8), pack-reused 0
Receiving objects: 100% (37/37), 10.57 MiB | 2.36 MiB/s, done.
Resolving deltas: 100% (8/8), done.
Submodule 'benchmarksql' (git@gitee.com:polardb-tianchi/benchmarksql.git) registered for path 'benchmarksql'
Submodule 'mysql-server' (git@gitee.com:polardb-tianchi/mysql-server.git) registered for path 'mysql-server'
Cloning into 'C:/Users/ybac2/Desktop/mysql_tpcc/mysql_tpcc_2024/benchmarksql'...
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@gitee.com:polardb-tianchi/benchmarksql.git' into submodule path 'C:/Users/ybac2/Desktop/mysql_tpcc/mysql_tpcc_2024/benchmarksql' failed
Failed to clone 'benchmarksql'. Retry scheduled
Cloning into 'C:/Users/ybac2/Desktop/mysql_tpcc/mysql_tpcc_2024/mysql-server'...
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@gitee.com:polardb-tianchi/mysql-server.git' into submodule path 'C:/Users/ybac2/Desktop/mysql_tpcc/mysql_tpcc_2024/mysql-server' failed
Failed to clone 'mysql-server'. Retry scheduled
Cloning into 'C:/Users/ybac2/Desktop/mysql_tpcc/mysql_tpcc_2024/benchmarksql'...
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@gitee.com:polardb-tianchi/benchmarksql.git' into submodule path 'C:/Users/ybac2/Desktop/mysql_tpcc/mysql_tpcc_2024/benchmarksql' failed
Failed to clone 'benchmarksql' a second time, aborting


git did not exit cleanly (exit code 1) (18687 ms @ 2024/10/12 17:38:15)

报错说我权限不够,我以为是SSH权限的问题,把自己的SSH重新在gittee上配置了一遍,发现还是报错。

如果问题一样的话,可以直接看思路二,直接的解决办法,思路一是曲线解决了问题,发现了问题的本质,才有了思路二。

思路一

这时候看到有篇博客说要修改子模块的拉取的路径,把git url,替换为https方式!

打开我的.git下的config文件

发现里面的子模块还真是git的拉取方式。

复制代码
[core]
	repositoryformatversion = 0
	filemode = false
	bare = false
	logallrefupdates = true
	symlinks = false
	ignorecase = true
[submodule]
	active = .
[remote "origin"]
	url = https://gitee.com/hair-monk/mysql_tpcc_2024.git
	fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
	remote = origin
	merge = refs/heads/master
[submodule "benchmarksql"]
	url = git@gitee.com:polardb-tianchi/benchmarksql.git
[submodule "mysql-server"]
	url = git@gitee.com:polardb-tianchi/mysql-server.git

现在手动去找到两个仓库的地址,并且把git的配置文件修改成https方式。

然后把这两个子模块的文件加删了,重新执行it submodule update --init

然后就可以拉下来了

思路二:

我们出问题的原因就是因为子模块和仓库的拉取方式不一样导致的,那我们刚刚也已经看了git的配置文件,配置文件中明确了子模块的拉取方式是git,而我刚开始拉取仓库的时候的拉取方式采用的Https的方式,所以才报错了,那我们拉取仓库的时候,直接使用git拉取, 让仓库和子模块的拉取方式保持一致不就行了?

就是这么简单,重新拉一下就好了:

git 复制代码
git clone  --recursive git@gitee.com:hair-monk/mysql_tpcc_2024.git

我刚开始复制地址的时候没看清,选择了Https方式的git clone没想到也成功了,如下指令

git 复制代码
git clone --recursive https://gitee.com/hair-monk/mysql_tpcc_2024.git

对此我不得不怀疑是因为使用图形化界面的原因了,以后还是少用图形化界面,都是问题。

相关推荐
qq_381013748 小时前
IntelliJ IDEA中GitHub Copilot完整使用教程:从安装到实战技巧
其他·github·intellij-idea·copilot
happyprince12 小时前
2026年04月07日热门github项目
github
奔跑草-12 小时前
【AI日报】每日AI最新消息2026-04-07
人工智能·大模型·github·开源软件
CoovallyAIHub12 小时前
Sensors 2026 | 从无人机拍摄到跑道缺陷地图,机场巡检全流程自动化——Zadar机场全跑道验证
数据库·架构·github
CoovallyAIHub13 小时前
15K Star中文首发!$5部署一个会自我进化的私人Agent——NousResearch开源Hermes Agent
git·架构·github
无限进步_14 小时前
【C++】巧用静态变量与构造函数:一种非常规的求和实现
开发语言·c++·git·算法·leetcode·github·visual studio
淼淼爱喝水14 小时前
Ansible 基础模块实战作业详细教程
chrome·github·ansible
高志小鹏鹏15 小时前
告别“修复 bug”:让别人一眼看懂你的 Commit
git·github·代码规范
李同学Lino16 小时前
别让你的 AI 太安逸!我给代码 Agent 装上了“大厂 PUA”插件,产出直接翻倍(附保姆级教程)
github
用户73654368074316 小时前
用 n8n + GitHub API 搭建 AI 开源项目自动监控系统(Docker 部署 + 评分模型 + Lark推送)
github