54

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?

4
  • Are you doing this from the command line / terminal or using VS Code's version control UI? Mar 19, 2020 at 12:36
  • @GinoMempin the UI I would not know exactly how to do it via command line
    – user180146
    Mar 19, 2020 at 12:52
  • How did you clone the repository on your local machine? Did you use HTTPS or SSH? Mar 20, 2020 at 4:41
  • For those coming from search engines searching for a solution to the Visual Studio Code scandal (the update of Visual Studio Code to version 1.62.2 (October 2021 1.62.0 release, 1.62.2 in November 2021) broke Git push to GitHub - symptom "No anonymous write access"): the Stack Overflow question Fix for "fatal: Authentication failed for" addresses this incident more directly (and is probably the canonical question for it). Nov 18, 2021 at 0:09

7 Answers 7

51

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.

2
  • 2
    Thanks for updating your answer. It works!
    – McGrew
    Nov 19, 2021 at 21:31
  • 2
    While this doesn't seem like the most ideal or "proper" solution, I can't argue with the results, as it fixed my issue when nothing else was working and I could not figure out the problem. I still don't understand what was going wrong with my setup or why it was failing, but at least now it is working, thank you very much. Apr 25, 2022 at 8:07
12

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

8
  • I followed all your steps. Nice and clear by the way thank you. When I tried to check the ssh key I got the following: Warning: Permanently added 'github.com.... But then I got the same message as you. So I thought it was fine. However in the second step of vs code I get the following error: Cloning into 'd:\Users\hillebr\Documents\2 - Test programma's\github-slideshow'... Warning: Permanently added the RSA host key for IP address ....... to the list of known hosts. [email protected]: Permission denied (publickey). fatal: Could not read from remote repository.
    – user180146
    Mar 20, 2020 at 8:40
  • What does ssh -T [email protected] give you? The warning about "Permanently added 'github.com' to the list of known hosts" is normal and expected. It's just telling you that "Hey, I'm going to use your SSH key on this machine to access Github". Mar 21, 2020 at 13:50
  • Looks fine: You've successfully authenticated, but GitHub does not provide shell access
    – user180146
    Mar 23, 2020 at 7:57
  • Hmm. Can you try going over the Github docs on Troubleshooting SSH > Error: Permission denied (publickey)? Usually, it's an incorrect git user configuration. Mar 23, 2020 at 11:25
  • 2
    If you already clone using https, you can switch the remote protocol via: git remote set-url origin [email protected]:USERNAME/REPO.git
    – Moop
    Nov 13, 2021 at 19:22
9

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:

5
  • Same issue with me after the latest update. But this didn't work for me
    – rajabraza
    Nov 21, 2021 at 17:37
  • @rajabraza which os are you using? and VS Code version? can you confirm, make sure you closed the terminal and opened a new one. Nov 21, 2021 at 19:56
  • Ubuntu 20.04. Yes, I even restarted the workstation as well. Also, I have upgraded the VSCode to version 1.62.3 but nothing helped.
    – rajabraza
    Nov 22, 2021 at 9:41
  • Version: 1.62.3 Commit: ccbaa2d27e38e5afa3e5c21c1c7bef4657064247 Date: 2021-11-17T08:00:36.721Z Electron: 13.5.2 Chrome: 91.0.4472.164 Node.js: 14.16.0 V8: 9.1.269.39-electron.0 OS: Linux x64 5.13.0-21-generic snap its working on mine, (versions are same as yours). Nov 22, 2021 at 19:03
  • This solution worked for me. In addition, I also reloaded my VS code. Apr 27 at 23:12
5

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.

1
  • 2
    This worked for me. Output of git remote -v gave me origin https://github.com/*my_github_username*/*github_reponame*.git (fetch) ... . I used git remote set-url origin [email protected]:YOURUSERNAME/reponame.git (I copied the corresponding part ([email protected]:YOURUSERNAME/reponame.git) directly from my github repo page in "Code" section/tab > then clicking the big green "Code" button with a dropdown menu > then selecting "SSH") Nov 23, 2021 at 3:06
2

Try to go through the terminal with sudo git push. If you have two-factor verification, use the token instead of the password like this:

Username for 'https://github.com': <username>

Password for 'https://[email protected]': <token>

1
2

You need to go back to the old version of Visual Studio Code and everything will be fine and all problems will be solved. It seems that the problem is in the latest version of Visual Studio Code and I hope it will be fixed. I am using Linux, an Ubuntu distribution.

September 2021 (version 1.61)

Enter image description here

0

What I have learn is that, You cloned the repository into an ssh terminal in vs-code. The first thing you could have done is to use gitbash terminal, it usually has this sign ">" as against the bash terminal which has a cube-like sign.

So before you clone a repository make sure you are using a gitbash terminal, hence, why the problem. Here is what I did. So since you used bash we have to play with "ssh".

First step, write this command in the repository you cloned

$ git config --global user.name "username in github"
$ git config --global user.email "email used in gihub"

Second Step

Follow this docs patiently

When you get to this step below in the document, continue below;

Step 2 Add your SSH private key to the ssh-agent. If you created your key with a different name, or if you are adding an existing key that has a different name, replace id_ed25519 in the command with the name of your private key file.

$ ssh-add ~/.ssh/id_ed25519

Instead of typing this command: $ ssh-add ~/.ssh/id_ed25519

Use this: ssh-add,

It will prompt you to enter paraphrase or something. type it.

Then make sure you have added the ssh key successfully by running this code:

ls -al ~/.ssh

try and cd to the directory of ssh

You should see something like this :

-rw--- 1 barry barry 465 Nov 1 07:47 id_ed23333
-rw--  1 jospeh jose 115 Nov 1 09:47 id_ed23333.pub

try and run this command:

cat id_ed23333.pub

It will give you; your ssh key copy it and go to your github account. After this go to your repository click on "code" you should see http /ssh click on "ssh', it should show you if you need to add an ssh key click on add key, name the key anything you want and paste the key you copied then add key.

Go back to vscode and rerun the usually code.

git add .
git commit -m "message"
git push

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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