'I get "You don't have permissions to push username/repository" on GitHub

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]



Solution 1:[1]

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.

Solution 2:[2]

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.

Solution 3:[3]

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jvet
Solution 2 VonC
Solution 3 Vandrey