Can't push to remote SSH repo on GitHub via VSCode

Viewed 43898

I already updated my Git for Windows. I checked the keys are correct. The only "solution" is to start

ssh-agent

Or opening VSCode via Git Bash.

So, any useful solution?

Log:

> git push origin master:master
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
3 Answers

Force push might be disabled on the master branch. Check the settings on the repo that you're trying to push to.

If force push on master is not disabled, you need to make sure that you have added your ssh key path on your ssh config, so that you don't have to add the ssh key to the session every time. Edit the config file at ~/.ssh/config and add the below (on MacOS)

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/path/to/key

For Windows, please check my SO answer to know how to add the ssh key to the ssh config.

UPDATE

Looks like there's an open issue with VS Code on Windows here. You may try the workaround that is mentioned here.

You could set an remote origin using an access token (in Github) like:
git remote set-url origin https://XXXX-YOUR-ACCESS-TOKEN-XXXXXX@github.com/your-account/your-repo.git

There are many ways you can make your ssh key (with a passphrase) works in the gitbash terminal for VS Code. I'll let you look around to find it if you didn't.

I assume you did look around and are still stuck because you want to use the UI of VSCode.

If so, this official page tells you why :

Basically, you'll still have to run it via git bash or via running ssh-agent.

But you can bypass the situation using putty. I didn't try it myself.

Anyway : hope it'll help.

Related