VS Code无法推送到git仓库,但git CLI可以。

huangapple go评论58阅读模式
英文:

VS Code can't push to a git repo, but git CLI can

问题

我已经通过git CLI克隆了一个仓库,就像这样:

git clone https://gitlab.myserver.com/myroot/myrepo.git/

然后在VS Code中,我在这个仓库上开发,并且可以在VS Code中提交我的更改。

但是当我尝试在VS Code中推送更改时,我收到以下git错误输出:

> git push origin main:main
fatal: 无法访问 'https://gitlab.myserver.com/myroot/myrepo.git/': 无法连接到服务器

然而,当我在命令行上推送时(通过 git push),我可以推送。

我应该如何在VS Code中修复这个问题?是因为我使用了HTTP(S)进行克隆吗?如果是的话,我应该如何告诉VS Code?

注意:我已经安装了一个SSH密钥。它位于正常的~/.ssh/位置(macOS)。不确定CLI是否在使用HTTPS远程时使用它们,但是CLI通过HTTPS访问是有效的。那么我应该如何告诉VS Code也使用HTTPS远程?

英文:

I have cloned a repo via the git CLI like this

git clone https://gitlab.myserver.com/myroot/myrepo.git/

Then in VS Code I develop on this repo and I can commit my changes in VS Code.

When I now try to push the changes in VS Code I get the following git-error output:

> git push origin main:main
fatal: unable to access 'https://gitlab.myserver.com/myroot/myrepo.git/': Couldn't connect to server

However when I push on the command line (via git push) I can push.

How can I fix this in VS Code? Is the problem that I used HTTP(S) for cloning? If so how do I tell VS Code about it?

Note: I have installed an ssh key. It is in the normal ~/.ssh/ location (macOS). No sure whether the CLI uses them with the HTTPS remote, but the CLI access via HTTPS works. So how can I tell VS Code to use the HTTPS remote as well?

答案1

得分: 1

你使用https是因为你克隆时使用的是这个协议,所以它不会使用你的ssh密钥。如果你想使用ssh,只需执行以下命令切换远程地址:

git remote set-url origin git@gitlab.myserver.com:myroot/myrepo.git
英文:

You're using https because that is what you cloned with, so its not going to use your ssh key at all. If you prefer to use ssh, just switch your remote with the following command:

git remote set-url origin git@gitlab.myserver.com:myroot/myrepo.git

huangapple
  • 本文由 发表于 2023年3月1日 15:57:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75600891.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定