Open In App

Git - How to Solve "remote: Invalid username or password. fatal: Authentication failed"?

Last Updated : 18 Nov, 2025
Comments
Improve
Suggest changes
7 Likes
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 simplest 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 a git repository and installing Git Bash

You will first create a git repository where you will be pushing all your project files. And for that, you need to have Git Bash installed (How to Install Git Bash 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 going to upload to the GitHub repository.

DEMO FILES
DEMO FILES

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

Checking GitBash
Checking Git Bash

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 Git Bash 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 Git Bash again and you will see that the error has been resolved 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).

Suggested Quiz
5 Questions

The error "remote: Invalid username or password. fatal: Authentication failed" usually occurs when:

  • A

    Git version is outdated

  • B

    Incorrect or invalid login credentials are used

  • C

    A repository has no commits

  • D

    You forgot to use git init

Explanation:

This error is triggered mainly when authentication fails due to wrong username/password, expired token, or 2FA-enabled account.

If GitHub has Two-Factor Authentication (2FA) enabled, what should you use instead of your regular password during Git operations?

  • A

    SSH key only

  • B

    Random password

  • C

    Personal Access Token (PAT)

  • D

    GitHub Desktop

Explanation:

When 2FA is enabled, GitHub disallows normal passwords for Git operations. A Personal Access Token acts as a secure password replacement.

Where can you generate a new Personal Access Token (classic) on GitHub?

  • A

    Repo → Code → Branches

  • B

    Profile → Repositories

  • C

    Settings → Developer settings → Personal Access Tokens

  • D

    Issues → Tokens

Explanation:

Tokens are created under GitHub Settings → Developer Settings → Personal Access Token → Tokens (classic).

If stored credentials become outdated after password change, what action will help resolve the authentication issue?

  • A

    Reinstall Git

  • B

    Generate a new PAT and use it during push

  • C

    Clone repo again

  • D

    Delete local project

Explanation:

Expired/saved credentials cause auth failure; generating and using a fresh token resolves it during push/pull operations.

After generating a token, what must be done when prompted for authentication during git push?

  • A

    Enter token instead of password OR sign in with browser

  • B

    Skip the login prompt

  • C

    Use git revert first

  • D

    Disable Git Bash

Explanation:

Git will ask for authentication during push; you must paste the PAT or authenticate through browser login to complete the process successfully.

Quiz Completed Successfully
Your Score :   2/5
Accuracy :  0%
Login to View Explanation
1/5 1/5 < Previous Next >

Explore