To use <git push> on Visual Studio Code, but show “Could not read from remote repository.”

I started studying Git and GitHub.

And now, I could create my repository to practice and I could push commits to origin repository(in GitHub) on git bash.

  • Remove files from Git commit
  • SSH to Openshift server fails
  • unable to update submodule
  • Android and version control systems, commit gen folder or put on ignore list?
  • git stash is slow on windows
  • Conflict on changes on git
  • But when I tried to push on Visual Studio Code, I have received this error

    Permission denied (publickey).

    fatal: Could not read from remote repository.

    and failed to push to origin repository.

    but I already remote local repository to origin repository with ssh key on git bash and I could complete push and pull between local repository and origin repository.

    In others’ case, they were asked GitHub credentials to push or sync, but in my case, I could not be asked any credentials like ssh key.

    In this case, What should I do? Thank you.

  • Docker-client Java API : The server failed to respond with a valid HTTP response
  • Github need login in console only for one repo
  • Clone GitHub Repository and Merge All Pull Requests
  • Make a Hosted Repository a submodule of another Hosted Repository in Phabricator
  • Is GIT a good solution for large projects like Laravel or projects using Smarty Templating
  • How do I get just the branch from a Git command?
  • 2 Solutions collect form web for “To use <git push> on Visual Studio Code, but show “Could not read from remote repository.””

    Your problems is that you probably didnt configured the right ssh keys.

    Simply follow those steps and you will set up your ssh key in no time:

    • Generate a new ssh key (or skip this step if you already have a key)
      ssh-keygen -t rsa -C "your@email"

    • Once you have your key set in home/.ssh directory (or Users/<your user>.ssh under windows), open it and copy the content

    How to add sh key to github account?

    • Login to github account
    • Click on the rancher on the top right (Settings)
      github account settigns
    • Click on the SSH keys
      ssh key section
    • Click on the Add ssh key
      Add ssh key
    • Paste your key and save

    And you all set to go 🙂

    I thought the answer by @codewizard was the correct one. Seems VS Code uses ‘’ key only, it was not using my other ssh key pair that git.exe was configured to use.(This key wasn’t name id_rsa.) However after generating a new id_rsa key pair, I still got permission denied (publickey).

    I Found my answer on this blog entry, seems vs code doesn’t have a ssh-agent to interact with?

    The solution on the blog being

    • Open a command prompt.
    • Run “start-ssh-agent” and answer passphrase
    • Run “code” to launch VS Code from that environment.

    I used git-bash
    start the ssh agent: eval "$(ssh-agent -s)"
    then "code" to launch VS Code

    git fetch started working. However I started to get a openssh passphrase box every x minutes(untimed)

    so I then rechecked the key was added
    again using git-bash
    then "ssh-add ~/.ssh/id_rsa"
    then git config --global credential.helper wincred

    If you want a password prompt every time, then ignore the two previous commands and disable autofetch in VS Code’s settings.
    "git.autofetch": "true" in VS code settings to "git.autofetch": "false"

    Git Baby is a git and github fan, let's start git clone.