Git 子模块 - 权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25957125/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:30:52  来源:igfitidea点击:

Git Submodule - Permission Denied

gitgithubgit-submodules

提问by Max

I am not able to clone the submodule existing within my private git repository. I do have access to entire repository,

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

Have used the below commands but dint work, please help. What is the right way to clone the submodules in an existing repository?

已经使用了以下命令,但不能正常工作,请帮忙。在现有存储库中克隆子模块的正确方法是什么?

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.

回答by arpiagar

I was facing the same issue. The problem was on your github repo , you might be using some old ssh key.

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

You need to update the current ssh key.

您需要更新当前的 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"

This worked for me !!

这对我有用!!

回答by SilentSteel

I had this issue. In my case, the public key (~/.ssh/id_rsa) wasn't set up on the server properly.

我有这个问题。就我而言,公钥 (~/.ssh/id_rsa) 未在服务器上正确设置。

Ensure you're getting all the submodules:

确保您获得所有子模块:

Reference: Git update submodule recursive

参考:Git 更新子模块递归

# 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

检查子模块的详细信息

  • Open .gitmodulesin the project root folder and ensure things look okay. As recommended by @VonC try cloning them in a separate folder.
  • You might want to switch submodules from using SSH to HTTPS. That will let you type a username and password. But that can cause issues with your teammates and build automation. Speak to them first.
  • .gitmodules在项目根文件夹中打开并确保一切正常。按照@VonC 的建议,尝试将它们克隆到单独的文件夹中。
  • 您可能希望将子模块从使用 SSH 切换到 HTTPS。这将让您输入用户名和密码。但这可能会导致您的队友出现问题并构建自动化。先跟他们说。

回答by Cem SOYDING

  • On Windows:
  • 在 Windows 上:

In my case, it was complaining about the same issue when I was using a regular command line (Git CMD). Then I tried with Git Bash and no issue no more.

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

回答by ?amo

In my case the issue was caused by console which did not ask me for a password. Solution was to change the console from CMDER to Gitbash. When I used CMDER it does not show the password window which caused this access denied issue.

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

回答by ang3lkar

Interestingly, in a similar occasion using the HTTPS link worked for me.

有趣的是,在类似的情况下,使用 HTTPS 链接对我有用。

回答by Pavel Pe?ina

Had the same problem with TortoiseGit / Windows subsystem for Linux / GitBash. The solution is to use authentication via an agent (key) instead of password.

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

For TortoiseGit:

对于TortoiseGit

  • run Pageant
  • add your key
  • enter password
  • TortoiseGit menu -> submodule update ...
  • 跑选美大赛
  • 添加您的密钥
  • 输入密码
  • TortoiseGit 菜单 -> 子模块更新 ...

(without pageant git clone it asks for password and works as intended, but git update fails with error)

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

For WS4L:

对于WS4L

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

proceed with git submodule update

与..一起处理 git submodule update

回答by doug nelson

i had created a submodule in error by using git init in a parent folder AND in its subfolder. Just removed the .git folder and started over with git init in the correct parent folder.

我通过在父文件夹及其子文件夹中使用 git init 错误地创建了一个子模块。刚刚删除了 .git 文件夹并在正确的父文件夹中使用 git init 重新开始。

回答by Abhinav Tripathi

Win10 + git bash terminal in VS Code. In my case, I was using git bash through VS Code. When using submodules, git pops up a window to enter pass phrase for the key. Bash through VSCode would't pop this up. With the windows Context menu item, "Git Bash Here" in the repo folder as shown below: Context menu Screen Grab

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

git submodule update

works splendidly.

工作出色。