This page looks best with JavaScript enabled

Fix Visual Studio Code Git with SSH in Windows 10

 ·  ☕ 4 min read

Read First

Note : assumption you use Git with SSH Key.

Do you use VSCode ( Visual Studio Code ) for daily programming in your Windows 10? there is very useful feature called Source Control in left side of VSCode layout ( currently my lowest VSCode version is 1.39 ). Do you use this feature?

If you use another Git GUI Client in windows and trying VSCode Source Control maybe facing problem with it. For example cannot pull from remote or push to remote. If yes then here I post about how to fix that problem in Windows ( in this post I use Windows 10 ).

Start Fix Git SSH Error

SSH-Agent

Windows 10 was shipped with OpenSSH feature so we can use that to use git. Let’s check it with opening Windows PowerShell and Run as administrator. Type command ssh-agent, if you face error message like unable to start ssh-agent service, error :1058 then you need to fix it.
Run this Set-Service ssh-agent -StartupType Manual to fix the error. This command tell that to set service of ssh-agent and I set to start ssh-agent to manual because I want to use it when I need it. You can use Set-Service ssh-agent -StartupType Automatic if you wish so.

Next you can start command ssh-agent again in Windows PowerShell as administrator.

SSH Key

If you have OpenSSH key then you can skip below list and move to add ssh.
Or if you have putty private key (.ppk) then you need to convert it to OpenSSH key (read number 1).
If you don’t have any key then create it first(read number 2).

  1. Open PuTTY Key Generator app and load your .ppk file and enter your passphrase. Open menu Conversions > Export OpenSSH key and put it in your desired directory.

  2. From Windows PowerShell run command git citool. In Git GUI open menu Help > Show SSH Key and then click button Generate Key.

Convert PuTTY key

If you not yet upload your public ssh key to repository like github or gitlab then upload it there. If you didn’t do it then this tutorial is not working 😂

Add SSH

In your Windows PowerShell run ssh-add path\to\your\openssh-key, for example ssh-add C:\Users\me\.ssh\id_rsa. Note that you need to give full path in windows style, when I try to give linux path style it’s not work (ex: ~/.ssh/id_rsa). Next enter your passphrase, when you do it right then you can check if your key is listed with command ssh-add -l.

Run Visual Studio Code

In Visual Studio Code I use Git Graph extension to make easy use Git in VSCode and it give graphical git history too… 👍 see: Git Graph extension

Note : assumption we use VSCode Git Graph extension.
If you have local git directory you can skip this paragraph. Pull/clone your git repository from Git Graph extension if you don’t have it yet. First, create a directory and name it what you like and open it in VSCode, from VSCode menu take View > Terminal and you can see terminal window at the bottom of VSCode. run git init in terminal. Next in Source Control (marked green in image below) you can set Git Graph icon on the left side of yellow mark. Open it and Git Graph window will open. Go to Repository Settings marked with red color. Add Remote and give it name origin, fetch url your repository ssh url (ex : git@gitlab.com:username/projectname.git), and skip push url. Next you can click Save Changes. If a window open then dismiss it. Next you need to clone it to you local drive, click icon with 3 dot (marked with yellow color) and Checkout to.. your master repository or any branch you want. And voila, your repository is clonned in your local with VSCode Source Control.

VSCode git mark

If you have local git directory that has been clonned before then you can directly open it with VSCode and the Source Control can be used as usual. You can pull, push, merge, commit, etc directly from VSCode without input your ssh passphrase again and again. 👍

OK, by now you can use VSCode Source Control and again, see you next time in the next post. Keep updating! 😉

Share on

AlextraPixel
WRITTEN BY
AlextraPixel
DIY Anywhere - Share any knowledge & Experience for everyone