git 无法通过 VSCode 推送到 GitHub 上的远程 SSH 存储库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52306173/
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-19 13:11:12  来源:igfitidea点击:

Can't push to remote SSH repo on GitHub via VSCode

gitsshvisual-studio-code

提问by dawn

I already updated my Git for Windows. I checked the keys are correct. The only "solution" is to start

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

ssh-agent

Or opening VSCode via Git Bash.

或者通过 Git Bash 打开 VSCode。

So, any useful solution?

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

Log:

日志:

> git push origin master:master
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

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

采纳答案by Madhu Bhat

Force push might be disabled on the master branch. Check the settings on the repo that you're trying to push to.

可能在主分支上禁用了强制推送。检查您尝试推送到的存储库上的设置。

If force push on master is not disabled, you need to make sure that you have added your ssh key path on your ssh config, so that you don't have to add the ssh key to the session every time. Edit the configfile at ~/.ssh/configand add the below (on MacOS)

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

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

For Windows, please check my SO answerto know how to add the ssh key to the ssh config.

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

UPDATE

更新

Looks like there's an open issue with VS Code on Windows here. You may try the workaround that is mentioned here.

看起来像有一个悬而未决的问题与VS代码在Windows这里。您可以尝试这里提到的解决方法。

回答by bail.organa

You could set an remote origin using an access token (in Github) like:
git remote set-url origin https://[email protected]/your-account/your-repo.git

您可以使用访问令牌(在 Github 中)设置远程源例如:
git remote set-url origin https://[email protected]/your-account/your-repo.git

回答by Nicolas HERMET

There are many ways you can make your ssh key (with a passphrase) works in the gitbash terminal for VS Code. I'll let you look around to find it if you didn't.

有很多方法可以使 ssh 密钥(带密码)在 gitbash 终端中为 VS Code 工作。如果你没有,我会让你环顾四周找到它。

I assume you did look around and are still stuck because you want to use the UI of VSCode.

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

If so, this official pagetells you why :

如果是这样,此官方页面会告诉您原因:

Basically, you'll still have to run it via git bash or via running ssh-agent.

基本上,您仍然必须通过 git bash 或通过 running 来运行它ssh-agent

But you can bypass the situation using putty. I didn't try it myself.

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

Anyway : hope it'll help.

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