-2

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?

halloleo
  • 9,216
  • 13
  • 64
  • 122
  • Do you have any ssh keys set up? Can vscode access them? – zerdox Mar 01 '23 at 08:01
  • when you push via https on commandline, do you get a prompt for credentials? If so, you could look at changing the way you specify your remote to pu the credentials in the remote url: https://stackoverflow.com/q/43069655/11107541 – starball Mar 01 '23 at 08:02
  • @user No, I don't get a prompt for credentials. (I guess because I have added an SSH key to the gitlab instance.) – halloleo Mar 01 '23 at 08:18
  • @zerdox Yes, I use an ssh key. It is in the normal `~/.ssh/` location (macOS). Can't VS Code use them? The CLI does do so. – halloleo Mar 01 '23 at 08:22
  • If this is your server, you can try to set up some tools (I am not sure which and how) to listen if your server even get any network requests. Maybe vscode is restricted with any sort of firewall? Are you able to use git in vscode with different repos on different hostings? On github? With https authentication? Can you define your issue so it can be more specific? Currently your question has hundreds of possible answers. I am sure you can debug this on your own without our help. Later you can share your own solution with us in QA format. Cheers. – zerdox Mar 01 '23 at 08:31
  • Yes, VS Code just makes calls to the git executable you have, so it supports SSH because your git executable does. You should change your remote url to use the ssh form using `git remote set-url `. – starball Mar 01 '23 at 08:33
  • ssh and https are different remote url forms. As far as my understanding goes, the https form will not use any of your SSH credentials and does not need them. – starball Mar 01 '23 at 08:34
  • And does not work. Use ssh, not https. – matt Mar 01 '23 at 11:25
  • @user Is there a way to tell VS Code to use the HTTPS access, not the SSH access. After all the git executable can do this on the command line. – halloleo Mar 03 '23 at 08:05
  • And @matt: Is there a way to tell VS Code to use the HTTPS access, not the SSH access. After all the git executable can do this on the command line. – halloleo Mar 03 '23 at 08:05

1 Answers1

1

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
Jonny Soe
  • 174
  • 8