【问题标题】:Can't push to remote SSH repo on GitHub via VSCode无法通过 VSCode 推送到 GitHub 上的远程 SSH 存储库
【发布时间】:2019-08-12 21:34:56
【问题描述】:

我已经更新了适用于 Windows 的 Git。我检查了密钥是否正确。唯一的“解决方案”就是开始

ssh-agent

或者通过 Git Bash 打开 VSCode。

那么,有什么有用的解决方案吗?

日志:

> git push origin master:master
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

【问题讨论】:

  • 强制推送可能在主分支上被禁用。检查您尝试推送到的存储库上的设置。
  • Madhu 所说的加:help.github.com/articles/…
  • @tymtam 我已经按照文章所说的做了,但无济于事。另外,我究竟如何启用“强制推送”?
  • 强制推送:git push --force
  • @tymtam 是的,我可以通过控制台推送它,但我想使用 VSCode GUI。

标签: git ssh visual-studio-code


【解决方案1】:

可能会在主分支上禁用强制推送。检查您尝试推送到的 repo 上的设置。

如果没有禁用对 master 的强制推送,您需要确保在 ssh 配置中添加了 ssh 密钥路径,这样您就不必每次都将 ssh 密钥添加到会话中。在~/.ssh/config 编辑config 文件并添加以下内容(在MacOS 上)

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/path/to/key

对于 Windows,请查看我的 SO answer 以了解如何将 ssh 密钥添加到 ssh 配置中。

更新

Windows here 上的 VS Code 似乎存在未解决的问题。您可以尝试here 提到的解决方法。

【讨论】:

  • 对于 Windows?
  • @dawn 添加到答案中。请查看我的 SO 答案,了解在 Windows 上添加它的步骤。
  • @dawn 你确定IdentityFile ~/.ssh/id_rsa之前没有#吗?由于# 可以注释该行。
  • @dawn 然后强制推送未被禁用。此外,ssh 配置应该具有您的 ssh 密钥的本地路径,而不是 ~/.ssh/id_rsa。如果您的 ssh 密钥在 D:\ssh_key 中,则应将行 IdentityFile D:\ssh_key 添加到 ssh 配置中。
  • @dawn 看起来 vscode github.com/Microsoft/vscode/issues/13680 存在未解决的问题。您可以尝试这里有人提到的解决方法github.com/Microsoft/vscode/issues/13680#issuecomment-414841885
【解决方案2】:

您可以使用访问令牌 (in Github) 设置远程源,例如:
git remote set-url origin https://XXXX-YOUR-ACCESS-TOKEN-XXXXXX@github.com/your-account/your-repo.git

【讨论】:

    【解决方案3】:

    有很多方法可以让你的 ssh 密钥(带有密码)在 VS Code 的 gitbash 终端中工作。如果你没有,我会让你四处寻找。

    我假设您确实环顾四周但仍然卡住,因为您想使用 VSCode 的 UI。

    如果是这样,this official page 会告诉你原因:

    基本上,您仍然需要通过 git bash 或运行 ssh-agent 来运行它。

    但是您可以使用putty 绕过这种情况。我自己没试过。

    无论如何:希望它会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-27
      • 2018-06-24
      • 2010-10-25
      相关资源
      最近更新 更多