Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 238
user180146 Avatar asked Mar 19 '20 12:03

user180146


People also ask

How do I push a Git code into Visual Studio?

To push the code to GitHub from Visual Studio Code, you will need to create a GitHub account and install the “Github Pull Requests and Issues” extension. Note: Before pushing the code from VS Code to GitHub, you need to ensure that all the files are in one folder, and you have to push your folder to Github.

Can't push to GitHub authentication failed?

The “fatal: Authentication failed” error message If you enabled two-factor authentication in your Github account you won't be able to push via HTTPS using your accounts password. Instead you need to generate a personal access token. This can be done in the application settings of your Github account.


4 Answers

A simpler method is to use personal access tokens at GitHub. This feature can be set up by going to your GitHub account → SettingsDeveloper settingsPersonal access tokensGenerate 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.

like image 143
sequence Avatar answered Oct 14 '22 00:10

sequence


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:

  1. 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
  2. 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,

  1. Clone your repo
    • Make sure to select the Clone with SSH option in GitHub enter image description here
  2. In VS Code, make sure to use that same [email protected]:..... URL enter image description here

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?.

like image 35
Gino Mempin Avatar answered Oct 13 '22 23:10

Gino Mempin


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.

  1. Open settings from the left bottom corner (Settings icon) or press CTRL+,
  2. type Authentication in the search option, it will show something like this. enter image description here
  3. You need to uncheck Git: Terminal Authentication. (e.g) enter image description here
  4. 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. enter image description here

on my end, everything is working fine. hope this works for you too. :slight_smile:

like image 7
Jahanzeb Nawaz Avatar answered Oct 14 '22 00:10

Jahanzeb Nawaz


After setting up the SSH key, you need to type this in your IDE (I'm using Visual Studio Code)

git remote -v

This will show you your current remote branch URL, but you can no longer use that.

To update it, type this in your console

git remote set-url origin [email protected]:YOURUSERNAME/reponame.git

Now try to push or make any changes

NOTE: From my perspective I think you'll have to perform this operation for all your existing (old) repositories too.

like image 4
Opeyemi Noah Avatar answered Oct 14 '22 00:10

Opeyemi Noah