在 Visual Studio Code 上使用 <git push>,但显示“无法从远程存储库读取”。
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34634364/
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
To use <git push> on Visual Studio Code, but show "Could not read from remote repository."
提问by Irrationnelle
I started studying Git and GitHub.
我开始学习 Git 和 GitHub。
And now, I could create my repository to practice and I could push commits to origin repository(in GitHub) on git bash.
现在,我可以创建我的存储库来练习,我可以在 git bash 上将提交推送到原始存储库(在 GitHub 中)。
But when I tried to push on Visual Studio Code, I have received this error
但是当我尝试推动 Visual Studio Code 时,我收到了这个错误
Permission denied (publickey).
fatal: Could not read from remote repository.
权限被拒绝(公钥)。
致命:无法从远程存储库读取。
and failed to push to origin repository.
并且未能推送到原始存储库。
but I already remote local repository to origin repository with ssh key on git bash and I could complete push and pull between local repository and origin repository.
但是我已经使用 git bash 上的 ssh 密钥将本地存储库远程到原始存储库,并且我可以在本地存储库和原始存储库之间完成推送和拉取。
In others' case, they were asked GitHub credentials to push or sync, but in my case, I could not be asked any credentials like ssh key.
在其他人的情况下,他们被要求提供 GitHub 凭据来推送或同步,但在我的情况下,我无法被要求提供任何凭据,例如 ssh 密钥。
In this case, What should I do? Thank you.
在这种情况下,我该怎么办?谢谢你。
回答by mushcraft
I thought the answer by @codewizard was the correct one. Seems VS Code uses 'id_rsa.pub' key only, it was not using my other ssh key pair that git.exe was configured to use.(This key wasn't name id_rsa.) However after generating a new id_rsa key pair, I still got permission denied (publickey).
我认为@codewizard 的答案是正确的。似乎 VS Code 仅使用 'id_rsa.pub' 密钥,它没有使用 git.exe 配置使用的其他 ssh 密钥对。(此密钥不是名称 id_rsa。)但是在生成新的 id_rsa 密钥对后,我仍然被拒绝(公钥)。
I Found my answer on this blog entry, seems vs code doesn't have a ssh-agent to interact with?
我在此博客条目中找到了答案,似乎 vs 代码没有可与之交互的 ssh-agent?
http://blog.alner.net/archive/2015/08/24/vs_code_with_git_ssh_keys_that_use_passphrases.aspx
http://blog.alner.net/archive/2015/08/24/vs_code_with_git_ssh_keys_that_use_passphrases.aspx
The solution on the blog being
博客上的解决方案是
- Open a command prompt.
- Run "start-ssh-agent" and answer passphrase prompts.
- Run "code" to launch VS Code from that environment.
- 打开命令提示符。
- 运行“start-ssh-agent”并回答密码提示。
- 运行“code”以从该环境启动 VS Code。
I used git-bash
start the ssh agent: eval "$(ssh-agent -s)"
then "code"
to launch VS Code
我使用 git-bash
启动 ssh 代理: eval "$(ssh-agent -s)"
然后"code"
启动 VS Code
Note:As @JoshuaH points out in the comments, you can create a windows shortcut to simply the steps above.
cmd /c start-ssh-agent & code
注意:正如@JoshuaH 在评论中指出的那样,您可以创建一个 Windows 快捷方式来简化上述步骤。
cmd /c start-ssh-agent & code
git fetch started working. However I started to get a openssh passphrase box every x minutes(untimed)
git fetch 开始工作。但是我开始每 x 分钟得到一个 openssh 密码框(不定时)
so I then rechecked the key was added
again using git-bash
then "ssh-add ~/.ssh/id_rsa"
then git config --global credential.helper wincred
所以我再复查,再次加入密钥使用Git的bash
然后"ssh-add ~/.ssh/id_rsa"
再git config --global credential.helper wincred
If you want a password prompt every time, then ignore the two previous commands and disable autofetch in VS Code's settings."git.autofetch": "true"
in VS code settings to "git.autofetch": "false"
如果你每次都想要密码提示,那么忽略前面的两个命令并在 VS Code 的设置中禁用自动获取。"git.autofetch": "true"
在 VS 代码设置中"git.autofetch": "false"
回答by CodeWizard
Your problems is that you probably didnt configured the right ssh keys.
您的问题是您可能没有配置正确的 ssh 密钥。
Simply follow those steps and you will set up your ssh key in no time:
只需按照这些步骤操作,您就可以立即设置 ssh 密钥:
Generate a new ssh key (or skip this step if you already have a key)
ssh-keygen -t rsa -C "your@email"
Once you have your key set in
home/.ssh
directory (orUsers/<your user>.ssh
under windows), open it and copy the content
生成一个新的 ssh 密钥(如果您已经有密钥,则跳过此步骤)
ssh-keygen -t rsa -C "your@email"
在
home/.ssh
目录中(或Users/<your user>.ssh
在 Windows 下)设置密钥后,打开它并复制内容
How to add sh key to github account?
如何将 sh 密钥添加到 github 帐户?
- Login to github account
- Click on the rancher on the top right (Settings)
- Click on the
SSH keys
- Click on the
Add ssh key
- Paste your key and save
- 登录github账号
- 点击右上角的牧场主(设置)
- 点击
SSH keys
- 点击
Add ssh key
- 粘贴您的密钥并保存
And you all set to go :-)
你们都准备好了:-)
回答by Tackle
My Bitbucket repo's remote was set up to use the[email protected]:teamname/reponame.git
SSH type of url.
我的 Bitbucket 存储库的遥控器设置为使用[email protected]:teamname/reponame.git
SSH 类型的 url。
With my passphrase enabled SSH key this was a no go.
I changed it to the HTTPS version:
https://[email protected]/teamname/reponame.git
使用我的密码短语启用 SSH 密钥,这是不行的。我把它改成了HTTPS版本:
https://[email protected]/teamname/reponame.git
Worked fine then. No need to work with other environments in Windows 10 etc.
那时工作得很好。无需在 Windows 10 等其他环境中工作。