Git push from Visual Studio Code: "No anonymous write access. Authentication failed"
I was following a tutorial from GitHub itself. I am following the one that teaches you to work from Visual Studio Code.
I was trying to push something from Visual Studio Code and after quite some time I get the following error:
remote: No anonymous write access.
fatal: Authentication failed for ....
Now I am pushing something to my personal account. I tried to google (but again I am new to this so I don't fully understand all the terminology) and what I could find are issues with two-factor authentication (but that is off in my case) and Windows credentials (but I checked and I do not have any Git in my Windows credentials).
So I am at a loss. What else I could try or check?
A simpler method is to use personal access tokens at GitHub. This feature can be set up by going to your GitHub account → Settings → Developer settings → Personal access tokens → Generate a personal access token. Make your access control selections, generate, then copy and save your new token. After this, go to your Git project directory and this enter in the terminal:
git remote set-url origin https://[email protected]/your_user/your_project.git
From now on you can easily do git push
from the terminal or Visual Studio Code.
VS Code just uses your environment's git configuration when it commits and pushes to the remote repo. So, you'll have to first make sure that your local env is set up correctly for Git, before worrying about VS Code.
1st, I recommend going through the First-Time Git Setup from the Git docs. The most important part there is setting-up your Git identity:
$ git config --global user.name "John Doe"
$ git config --global user.email [email protected]
2nd, I recommend setting-up SSH keys on your local machine and on your GitHub profile. GitHub has an entire tutorial on Connecting to GitHub with SSH.
Basically:
- Generate a SSH key on your machine (Generating a new SSH key)
- There's a step there that specifies
-C "[email protected]"
- Make sure that it matches the git
user.email
that you set as your Git identity
- There's a step there that specifies
- Add that SSH key to your GitHub account, in the SSH and GPG keys section.
You can check that your SSH keys are valid by entering this in the terminal:
$ ssh -T [email protected]
Hi ginomempin! You've successfully authenticated, but GitHub does not provide shell access.
Now,
- Clone your repo
- Make sure to select the Clone with SSH option in GitHub
- In VS Code, make sure to use that same [email protected]:..... URL
I do not have any Git in my Windows credentials
You can choose to disable that entirely, as I find that the Windows credentials manager can cause problems, and using SSH is more "stable". See How do I disable Git Credential Manager for Windows?.
Yahooo! Finally, an Issue resolved
This is only for those who are facing this issue from the last update of VS Code. (NOV 15, 2021 or around)
The issue on Github Community #LINK
No need to downgrade VS Code, or git version. basically what I understood from the fix that worked for me. think it's a sort of conflict between GitHub and Git authentication.
So there are a few steps you can try and hopefully, it would be fixed for you too.
Open your Settings In VS CODE.
- Open settings from the left bottom corner (Settings icon) or press
CTRL+,
- type Authentication in the search option, it will show something like this.
- You need to uncheck Git: Terminal Authentication. (e.g)
- Only Github: Github Authentication should be checked.
Now you need to close the opened terminal (if any). open your new terminal and try with git commands.
on my end, everything is working fine. hope this works for you too. :slight_smile: