Git子模块 - 权限被拒绝

问题描述 投票:12回答:8

我无法克隆我的私有git存储库中存在的子模块。我有权访问整个存储库,

使用了以下命令但没有用,请帮忙。克隆现有存储库中子模块的正确方法是什么?

djrecker$ git submodule update --init --recursive
Submodule 'Path' ([email protected]:Path) registered for path 'App'
Cloning into 'Path'...
Permission denied (publickey).
fatal: Could not read from remote repository.
git github git-submodules
8个回答
28
投票

我面临同样的问题。问题出在你的github repo上,你可能正在使用一些旧的ssh密钥。

您需要更新当前的ssh密钥。

Steps involved are:

1. vim ~/.ssh/id_rsa.pub
2. copy the ssh key
3. Go to the github settings
4. Select the option ssh keys
5. Remove the old ssh keys not used anymore.
6. Add a new ssh key.
7. Try running the "git submodule update --recursive"

这对我有用!!


10
投票

我有这个问题。在我的情况下,没有在服务器上正确设置公钥(〜/ .ssh / id_rsa)。

Ensure you're getting all the submodules:

参考:Git update submodule recursive

# This must be called twice. Once for new and once for existing submodules.
git submodule update --init --recursive
git submodule update --recursive

To diagnose permission issues with your key:

To check details of your submodules

  • 在项目根文件夹中打开.gitmodules并确保看起来没问题。根据@VonC的建议,尝试将它们克隆到单独的文件夹中。
  • 您可能希望将子模块从使用SSH切换到HTTPS。这将允许您键入用户名和密码。但这可能会导致您的队友出现问题并构建自动化。先与他们交谈。

4
投票
  • 在Windows上:

就我而言,当我使用常规命令行(Git CMD)时,它抱怨同样的问题。然后我尝试了Git Bash,没有任何问题。


3
投票

有趣的是,在类似的场合使用HTTPS链接为我工作。


0
投票

在我的情况下,问题是由控制台引起的,它没有要求我输入密码。解决方案是将控制台从CMDER更改为Gitbash。当我使用CMDER时,它没有显示导致此访问被拒绝问题的密码窗口。


0
投票

用于Linux / GitBash的TortoiseGit / Windows子系统存在同样的问题。解决方案是通过代理(密钥)而不是密码使用身份验证。

对于TortoiseGit:

  • 跑选
  • 添加你的密钥
  • 输入密码
  • TortoiseGit菜单 - >子模块更新...

(没有选美git clone它要求输入密码并按预期工作,但git update失败并出现错误)

对于WS4L:

$ eval `ssh-agent -s`
$ chmod 600 /path/to/key
$ ssh-add /path/to/key

继续git submodule update


0
投票

我在父文件夹和子文件夹中使用git init创建了一个错误的子模块。刚刚删除了.git文件夹,并在正确的父文件夹中使用git init重新启动。


-1
投票

VS Code中的Win10 + git bash终端。就我而言,我通过VS Code使用git bash。使用子模块时,git弹出一个窗口输入密钥的密码短语。 Bash通过VSCode不会弹出这个。使用windows上下文菜单项,repo文件夹中的“Git Bash Here”,如下所示:Context menu Screen Grab

git submodule update

工作出色。

© www.soinside.com 2019 - 2024. All rights reserved.