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

533 views Asked by At

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

There are 1 answers

0
Jonny Soe On

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 [email protected]:myroot/myrepo.git