How to Fix Github Fatal Error: Authentication Failed From VSCode Terminal

You might have come across this error once or twice in your development journey with Visual Studio Code. In most cases, this error appears when you are about to push some code to your Github repository using the VS Code terminal.

You just run the ‘git push’ command and suddenly this weird error appears that says:

fatal: Authentication failed for ''

There’s no need to panic though. Some users have actually un-committed or un-staged there code changes after seeing this error which really makes no sense.

Most common reason

Usually, this error happens when you have recently updated or upgraded your VS code and then you made some changes to your code to push it to your Github repo. In that case, you simply need to re-connect your VS code with your Github account to restore the connection.

The Solution

Here I am going to take you step-by-step on how to fix this error in no time. Heck, I am even going to share some screenshots so that you don’t have to figure out anything by yourself.

Here’s how you can re-authenticate your VS code to your Github account:

  1. First step is to Login to your Github account.
  2. Then go to your Github settings.
    github settings
  3. After that, you need to go to the ‘Developer Settings”.
    Github Developer Settings
  4. Then, you need to click on the ‘Tokens (classic)’ button. This will take you to the Tokens screen. This option will appear after expanding the ‘Personal Access Tokens’ button.
    Tokens classic
  5. Next, you need to click on the “Generate new token (classic)” option. This will take you to the Token generation screen.
    Generate new Token
  6. In the next step, you can setup a custom expiration time for your token. Just remember, when the token expires, you will have to repeat the same process to authenticate with Github.
    Generate Github Token
  7. Now, just click on the green ‘Generate Token’ button at the bottom of the screen. Note: Make sure you only enable the Workflow setting.
    Enable workflow setting
  8. In the next screen, you need to copy the token so you can insert it into VS code. Please note that you will only be able to see this token once. If you don’t copy and and exit this screen, you will have to generate a new token.
    Personal Access Token
  9. Now here’s the most important step. You need to insert this token in your VS code to authenticate it with Github. Open your VS code terminal and set the current directory to your Project root. For example:
    cd C:\Users\test\source\repo\MyTestProject
  10. Then enter this command to set Remote access via your Github token:
    git remote set-url origin
    Replace the ‘username’ and ‘token’ with your Github username and personal access token that you copied. Also replace the repository name in the url.
  11. After doing all this, you should be able to push your code to your Github Repo.

If it still doesn’t work, you might have to restart VS code and then try to push the commits again.

Spread the Word

You May Also Like

About the Author: Umair

A self-learned Javascript developer specializing in Frontend and Backend frameworks including React.js, Redux, Node.js, Express, MongoDB. He has extensive industry experience as a Tech Support lead and System Administrator. Currently learning Web3, (Solidity, Hardhat, Ethers.js) Smart contracts development, testing and auditing.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.