5

I am working with a Mac M1.

Last week I was working fine with VSCode and Github. I was editing some markdown files and pushing the changes I made to the files. However, I deleted my account from GitHub, created a now I'm getting that permission error. I have tried for 3 hours and even created an SSH key again that I added to GitHub, but still I cannot get it to work.

The last thing I tried was cloning the repo, adding it to vscode, pasting the files inside the folder associated to the repo, but when I tried to push the changed I got the error again.

I can do it using the GitHub desktop app, the issue is with VSCode.

Help please.

[![Permission error][1]][1]

4 Answers 4

6

This is how I managed to fix Permission denied to... error while pushing after switching gitHub accounts on Windows.


  1. ( Recommended ) Close all IDE/editors/terminals just in case and makes sure you know you gitHub credentials.
  2. Go to Windows credential manager
  3. Find git:https://github.com
  4. Delete ( You can also remove VSCodedevvscode.github-authenthication if you use that or log out from within VSC )
  5. Add your remote again e.g. as mentioned in notes.

Additional notes:

  • Windows 11
  • GitHub remote repository was previously added via https://github.com/...
  • Credentials where added via gitHub login popup redirected to browser

0

Found the answer here: Freecodecamp

What I did is typing this in the terminal:

git remote set-url origin [email protected]:MrsColombo/elsevier-twitter-rest-api.git

Changing de git@github to my repo code.

0

If you still got the error (before switching to an SSH URL) that means:

  • your clone was initially done with an HTTPS URL
  • your Mac Credential manager has your old credentials (old Github user account name/password) stored in it.

Check what your credential helper is:

git config credential.helper
xxx

(xxx could be, for instance, osxkeychain, as described in this article)

Then, assuming git-credential-osxkeychain is in your $PATH (if not, use its absolute path)

printf "protocol=https\nhost=github.com"| git-credential-osxkeychain erase
printf "protocol=https\nhost=github.com\nusername=MrsColombo\npassword=<yourNewPassword>"| git-credential-osxkeychain store

# check it worked with:
printf "protocol=https\nhost=github.com"| git-credential-osxkeychain get

That way, you can resume using SSH or, in this case, HTTPS GitHub URLs.

0

I also got this problem. I solved it by looking in the Git log:

It said something along the lines of "Permission denied to ". It seems as if Visual Studio Code was using my Visual Studio GitHub Settings, although I installed Git for Windows seperately. Since I didn't need the GitHub account on my normal Visual Studio anymore, I just logged out and retried the push. Then it redirected to GitHub again and asked for my credentials and permissions, which I granted. That way it worked.

Very weird that Git on VS Code is dependent on VS and it mixes things up. Very unfortunate if you still need to use both of those.

Not the answer you're looking for? Browse other questions tagged or ask your own question.