如何在Git子模块中使用SSH而不是HTTP?

ma1*_*w28 5 git ssh github git-clone git-submodules

为什么人们有这个问题?

$ git clone --recursive git@github.com:acani/Chats.git克隆到'聊天'...权限被拒绝(公钥).致命:无法从远程存储库读取.

请确保您具有正确的访问权限并且存储库存在.

https://github.com/acani/Chats/issues/53#issuecomment-118014684

我已经阅读了一些答案,说要将子模块URL从SSH更改为HTTP,但为什么我必须这样做.我不想那样做.我想保留SSH,这样如果我想推送,我就不必在终端输入我的用户名和密码.每个人都可以很好地克隆SSH URL,那么他们为什么不能将它作为子模块递归克隆呢?

Von*_*onC 5

作为解决方法,您可以尝试使用https url进行任何github repo:

cd myParentRepo
git config url.https://github.com/.insteadOf ssh://git@github.com/
# or
git config url.https://github.com/.insteadOf git@github.com:
Run Code Online (Sandbox Code Playgroud)


ma1*_*w28 4

SSH 协议不支持对 Git 存储库的匿名访问。

\n\n

因此,不要使用 SSH 协议。相反,请使用智能 HTTP 协议(​​推荐)或 Git 协议。

\n\n

对于存储库.gitmodules文件中的每个子模块 URL,请替换git@github.com:https://github.com/(使用智能 HTTP 协议)或git://github.com/(使用 Git 协议)。

\n\n

更多信息:Git - 协议

\n