Getting VS Code source control working

Jeff P
3 min readOct 18, 2023

--

Had some issues being able to push commits to github via VS code. Was getting public key errors and issues with credentials.

This is what I did to get it working:

  1. check you have a .ssh folder in your Windows user profile:

If the folder doesn’t exist, you can create it by typing in the following in a command prompt:

ssh-keygen -t ed25519

If you use the defaults then it will save your keys in C:\User[YourUserName].ssh — assuming the C drive is where your user account is stored.

Your keys are then created, saved, and ready for use. You will see you have two files in your “.ssh” folder: “id_rsa” with no file extension and “id_rsa.pub.” The latter (id_rsa.pub) is the key you upload to servers to authenticate while the former is the private key that you don’t share with others.

2. Add the id_rsa.pub SSH key to github in settings:

3. Test it’s working to be able to push from git via the command line:

IF you get the following when trying to perform as git push….

then you probably need to remove old instances of github from the /.ssh/known_hosts file

It could be that there’s an issue with using the old RSA SSH host key which github changed:

4. Now try comiting and pushing from vs code. IF it still doesn’t work, try this which is what eventually worked from me, by running the following four commands from Windows PowerShell (as Administrator):

Get-Service -Name ssh-agent | Set-Service -StartupType Manual
ssh-agent
ssh-add
git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe

I also had to run this code so that VS code clones repos via ssh instead of the default https:

Set SSH as Default for Git: Open a terminal or command prompt and set SSH as the default protocol for Git:

git config --global url."git@github.com:".insteadOf "https://github.com/

--

--

Jeff P
Jeff P

Written by Jeff P

I tend to write about anything I find interesting. There’s not much more to it than that really :-)

No responses yet