Skip to content

Instantly share code, notes, and snippets.

@atulkumar2
Last active April 19, 2023 11:57
Show Gist options
  • Save atulkumar2/bc3080661b6ad89952d2bedc0bb2fdde to your computer and use it in GitHub Desktop.
Save atulkumar2/bc3080661b6ad89952d2bedc0bb2fdde to your computer and use it in GitHub Desktop.
Use git to interact with github in VSCode on windows 11

Use git to interact with github in VSCode on windows 11.

Github no longer allow password based authentication so SSH is the one way to avoid convoluted authentication via browser.

Installation

Open windows terminal and start a git bash session.

Adding SSH keys

In Git bash windows on windows terminal, Run the command to start SSH agent

  • eval "$(ssh-agent -s)"
  • ssh-add ./new_key_file
  • copy content of ./new_key_file.pub in github account

Now, we can use git commands in the git bash terminal to interact with github.

Use git commands in VScode terminal

To be able to interact with github in vscode, we need to start vscode from git bash. Check Github with vscode

  • code .

If we do not want to start vscode from git bash, we need to do below

  • Open git bach terminal in windows terminal and run the commands as below
  • eval "$(ssh-agent -s)"
  • ssh-add ./new_key_file
  • In VScode, open terminal and run below command
  • cmd /c start-ssh-agent

Just doing start-ssh-agent in any powershell terminal starts a cmd shell which restricts ability of the powershell terminal. You can see in the vscode that the terminal type changes from posh to cmd.

Check out ssh-add on windows 10 for details on running ssh-agent automatically at startup.

An easier way found working with bitbucket

Setting up personal key for bitbucket

Make sure that OpenSSH is installed. Details are in the above link.

Open powershell admin console and run below

  • Set-Service -Name sshd -StartupType 'Automatic'
  • Start-service ssh-agent
  • Get-service ssh-agent

Open normal Powershell and run comamnds as follows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment