Open In App

Git – How to Solve “remote: Invalid username or password. fatal: Authentication failed”?

Last Updated : 26 Jun, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Encountering the “remote: Invalid username or password. fatal: Authentication failed” error can be frustrating, especially when you’re trying to push or pull changes to a Git repository. This issue is commonly related to authentication problems with your Git remote repository. In this article, we’ll explore the reasons behind this error and provide step-by-step solutions to resolve it.

Common Causes of the Error

  1. Incorrect Username or Password: The most simple reason is entering the wrong username or password.
  2. Outdated Credentials: Saved credentials that are no longer valid can cause this error.
  3. Two-Factor Authentication (2FA): If 2FA is enabled on your Git hosting service, your regular password won’t work.
  4. Changed Password: If you’ve recently changed your password, your saved credentials may be outdated.
  5. Token Expiry: If you’re using a personal access token (PAT), it might have expired.

Steps to Solve the Error

Step 1: Creating git repository and installing GitBash

You will first create a git repository where you will be pushing all your project files. And for that, you need to be installed with GitBash too (How to Install Gitbash and How to Work and Push Code on Git Repository?)

Once you are familiar with the above things, you can now move ahead with the article which will be focusing on the git error (remote: Invalid username or password / fatal: Authentication failed).

Step 2: For demonstration purposes, we have created a dummy git repository that looks something like the image attached below.

Creating dummy git repo

Creating dummy git repo 

Created successfully and prompted with quick setup

Created successfully and prompted with quick setup

Following image attached below shows the files which we are gonna upload to the GitHub repository.

DEMO FILES

DEMO FILES

Step 3: Checking whether GitBash has been installed on our machine successfully or not.

Checking GitBash

Checking GitBash

Step 4: Once Steps 2 and 3 is been done

If while doing step 2 i.e. following the quick setup tutorial or the article which is attached in step 1 on how git works, if you are prompted with the error (remote: Invalid username or password / fatal: Authentication failed) i.e. as shown in the image attached below. Then this article is gonna focus on that error only.

error

error

Step 5: Solve the error

A) Go to settings in your Github account >> Developer settings >> Personal access token >> Tokens (classic) >> Generate new token. See the images attached below for a better understanding.

A) 1

A) 2

A) 3

A) 4

For generating tokens you can follow up on this article (How to Create GitHub Personal Access Token).

B) Once you are ready with the token go again to your GitBash terminal and execute the push command. You will be redirected to a popup as shown in the image below:

POPUP

POPUP

C) Next, here in the pop-up tab you can:

  1. Simply copy and paste the token which you have generated just now.
  2. Or, you can go ahead and click on Sign in with your browser.

Once that is done you have finally reached your destination, you will be redirected to a new page saying, see the image below.

Succeded

Succeeded

Once this is done close the tab and go to GitBash again and you will see the error is been solved and all the files must be uploaded successfully.

UPLOADED successfully

UPLOADED Successfully

You can also visit the GitHub repository and see your files have been uploaded successfully without the error (remote: Invalid username or password / fatal: Authentication failed).

Verifying by visiting GitHub repo (UPLOADED successfully)

Verifying by visiting the GitHub repo (UPLOADED successfully)

In this way, you can add your Project files to the GitHub repository without the git error i.e. (remote: Invalid username or password / fatal: Authentication failed).



Next Article

Similar Reads