git - 在 Visual Studio Code 上使用 <git push>,但显示 "Could not read from remote repository."

标签 git github visual-studio-code

我开始学习 Git 和 GitHub。

现在,我可以创建我的存储库来练习,我可以在 git bash 上将提交推送到原始存储库(在 GitHub 中)。

但是当我尝试在 Visual Studio Code 上推送时,我收到了这个错误

Permission denied (publickey).

fatal: Could not read from remote repository.

无法推送到原始存储库。

我已经在 git bash 上使用 ssh key 将本地存储库远程连接到原始存储库,并且我可以在本地存储库和原始存储库之间完成推送和 pull 。

In others' case ,他们被要求提供 GitHub 凭据以进行推送或同步,但在我的情况下,我无法被要求提供任何凭据,例如 ssh key 。

遇到这种情况,我该怎么办?谢谢。

最佳答案

我认为@codewizard 的回答是正确的。似乎 VS Code 仅使用“id_rsa.pub” key ,它没有使用我配置为使用 git.exe 的其他 ssh key 对。(此 key 不是名称 id_rsa。)但是在生成新的 id_rsa key 对之后,我仍然被拒绝许可(公钥)。

我在这篇博文中找到了我的答案,似乎 vs code 没有可以交互的 ssh-agent?

http://blog.alner.net/archive/2015/08/24/vs_code_with_git_ssh_keys_that_use_passphrases.aspx

博客上的解决方案是

  • 打开命令提示符。
  • 运行“start-ssh-agent”并回答密码 提示。
  • 运行“code”以从该环境启动 VS Code。

我用的是 git-bash
启动 ssh 代理:eval "$(ssh-agent -s)"
然后 "code" 启动 VS Code

注意:正如@JoshuaH 在评论中指出的那样,您可以创建一个 Windows 快捷方式来简化上述步骤。 cmd/c start-ssh-agent & 代码

git fetch 开始工作了。但是我开始每隔 x 分钟(未计时)得到一个 openssh 密码框

所以我重新检查了 key 是否已添加 再次使用 git-bash
然后 "ssh-add ~/.ssh/id_rsa"
然后 git config --global credential.helper wincred

如果你每次都想要密码提示,那么忽略前面的两个命令并在 VS Code 的设置中禁用自动获取。
"git.autofetch": "true" 在 VS code 设置为 "git.autofetch": "false"

关于git - 在 Visual Studio Code 上使用 <git push>,但显示 "Could not read from remote repository.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34634364/

相关文章:

git - 忽略 repo 中已有的文件而不删除它们

search - 搜索 GitHub 的最佳方式是什么?

javascript - 来自内置语言扩展的项目范围的 Javascript/TypeScript 语言错误

bash - VScode 终端似乎没有在 Windows 上加载 .bashrc 或 .bash_profile

typescript - npm 不更新 tsc 版本

git - 为什么我的远程 Git 存储库在推送到它之后有未提交的更改?

git - 如何将本地分支恢复到 github 中的状态?

ruby-on-rails - 安装sqlite3(1.3.11)时出错,Bundler无法继续

git - 我在 git clone 上收到 500 错误

node.js - commitlint config-conventional - 为提交消息添加前缀