gitgithubvisual-studio-code

Visual Studio Code: Push to git works from Terminal but not when using the user interface


Running Windows 8.1 64-bit with the following installed:

My personal SSH key (located at %USERPROFILE%\.ssh) has been generated and added to my GitHub account. .bashrc located at %USERPROFILE has been modified to add these lines:

# Start ssh-agent to allow git to be used
eval `ssh-agent -s`
ssh-add ~/.ssh/id_rsa_personal

I start Git Bash (MINGW64) in a git repo. Now make changes to a file, git add, git commit and git push the changes to my git repo...and it works fine!

For the standard Windows command prompt, I've created a file called bashrc.cmd with this code:

rem Start ssh-agent to use git from the Windows command line
set GIT_PATH=C:\Program Files\Git
call "%GIT_PATH%\cmd\start-ssh-agent.cmd"
call "%GIT_PATH%\usr\bin\ssh-add.exe" "%USERPROFILE%\.ssh\id_rsa_personal"

Now, a new REG_SZ value called AutoRun in the key HKLM\SOFTWARE\Microsoft\Command Processor was created which points to the above file (bashrc.cmd)

Start a command prompt, and now ssh-agent is started and my identity is added. As with Git Bash, add, commit and push work perfectly. Awesome!

Now I load Visual Studio Code in my git repo. In the lower left, Code knows I'm inside a git repo:

master branch of my repo

Using the in-built Terminal in Code, I can add, commit and push changes to my git repo. Great!

But now I try it with the user interface buttons. I can stage and commit changes and confirm in a separate command line windows using git status that these work as expected. But when I use the Push command, I get this error:

Permission denied to git repo

Return to the Code Terminal, or a Windows command prompt, or Git Bash, issue the command git push and the changes are sent to the remote repo correctly.

Why is this not working with the Code Push command?


Solution

  • After some efforts I found same error in my Visual Studio Code, even when I tried to use ctrl+shift+p and git:pull command also gives me the same error as describe Permission Denied(publickey)

    I read here, that Seems VS Code uses 'id_rsa.pub' key only, and I'm having different name for the key pairs, then I copies private key and public key which was set for the git repository to id_rsa and id_rsa.pub and again I tried to check with icons as well as from menu and it works without adding into ssh-agent because it only search for ~/.ssh/id_rsa at your profile directory. When I deleted id_rsa it gives me the same error and terminal is working as expected with the different key name which is already added in ssh-agent.

    Also the thing is, git add . and git commit -m are the commands which works for local not establish connection with remote branch but when you tries to fetch, pull, push tries to connect to remote repository where authentication is required.