Can't push to remote SSH repo on GitHub via VSCode
Can't push to remote SSH repo on GitHub via VSCode
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.
What Madhu said plus: help.github.com/articles/…
– tymtam
Sep 13 '18 at 3:23
@tymtam I already did what the article says with no avail. Also, how exactly do I enable 'Force push'?
– dawn
Sep 13 '18 at 3:32
Force push: git push --force
– tymtam
Sep 13 '18 at 4:07
@tymtam yeah, I can push it via console, but I want to use VSCode GUI.
– dawn
Sep 13 '18 at 4:10
2 Answers
2
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)
config
~/.ssh/config
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.
And for Windows?
– dawn
Sep 13 '18 at 3:32
@dawn added to the answer. Please check my SO answer for the steps to add it on Windows.
– Madhu Bhat
Sep 13 '18 at 3:34
@dawn Are you sure there is no
#
before IdentityFile ~/.ssh/id_rsa
? Since the # can comment the line.– Madhu Bhat
Sep 13 '18 at 3:37
#
IdentityFile ~/.ssh/id_rsa
@dawn then force push is not disabled. Also, the ssh config should have the local path to your ssh key and not
~/.ssh/id_rsa
. If your ssh key is in D:ssh_key, you should add the line IdentityFile D:ssh_key
to the ssh config.– Madhu Bhat
Sep 13 '18 at 3:43
~/.ssh/id_rsa
IdentityFile D:ssh_key
@dawn looks like there's an open issue with vscode github.com/Microsoft/vscode/issues/13680. You may try this workaround that someone has mentioned here github.com/Microsoft/vscode/issues/13680#issuecomment-414841885
– Madhu Bhat
Sep 13 '18 at 4:05
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
.
ssh-agent
But you can bypass the situation using putty. I didn't try it myself.
Anyway : hope it'll help.
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Force pushes might be disabled on the master branch. Check the settings on the repo that you're trying to push to.
– Madhu Bhat
Sep 13 '18 at 3:22