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

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

相关推荐
正经教主9 小时前
【Git】Git05-04:Github分支管理与协作流程
git·github
CoderJia程序员甲11 小时前
GitHub 热榜项目 - 日榜(2025-11-22)
ai·开源·llm·github·ai教程
小Lu的开源日常11 小时前
踩坑日记:为什么Git 突然 Push 不上去了
git·ssh·github
LZ7工作室12 小时前
MAC编程:在MACOS安装和使用 Git 的方法
网络·git·macos·github·个人开发
skywalk816317 小时前
github创建项目后,应该用main还是master作为默认branch?
git·github
正经教主17 小时前
【Git】Git07:GitHub desktop使用教程【可选】
git·github
CoderJia程序员甲19 小时前
GitHub 热榜项目 - 日榜(2025-11-20)
ai·开源·大模型·github·ai教程
JinSo1 天前
Ultracite:为 AI 时代打造的零配置代码规范工具
前端·javascript·github
uhakadotcom1 天前
Next.js 从入门到精通(1):项目架构与 App Router—— 文件系统路由与目录结构全解析
前端·面试·github
x***58702 天前
GitHub星标10万+的Redis项目,使用教程
数据库·redis·github