Git – How to Solve “remote: Invalid username or password. fatal: Authentication failed”?
Last Updated :
26 Jun, 2024
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
- Incorrect Username or Password: The most simple reason is entering the wrong username or password.
- Outdated Credentials: Saved credentials that are no longer valid can cause this error.
- Two-Factor Authentication (2FA): If 2FA is enabled on your Git hosting service, your regular password won’t work.
- Changed Password: If you’ve recently changed your password, your saved credentials may be outdated.
- 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Â

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
Step 3: Checking whether GitBash has been installed on our machine successfully or not.

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
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
C) Next, here in the pop-up tab you can:
- Simply copy and paste the token which you have generated just now.
- 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.

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
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 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).
Similar Reads
How to Fix "Support for password authentication was removed."?
With the increasing focus on security in software development and deployment, many platforms are moving away from less secure methods of authentication. GitHub, in particular, has deprecated password-based authentication for Git operations, encouraging users to adopt more secure methods such as pers
3 min read
How to Save Username And Password in Git?
Managing credentials efficiently is important for seamless interaction with remote Git repositories. By default, Git prompts for a username and password each time you interact with a remote repository. To simplify this process, you can configure Git to save your credentials, allowing for a smoother
3 min read
How to Set Git Username and Password in GitBash?
Setting up your Git username and password is an essential step when working with Git repositories. It helps you confirm your identity when sending (pushing) changes or getting (pulling) updates from a remote repository. In this guide, we will show you how to easily set your Git username and password
3 min read
How To Fix âCould Not Open A Connection To Your Authentication Agentâ In Git?
When working with Git, especially for operations that involve authentication, such as pushing to a remote repository, you might encounter the error message: Could not open a connection to your authentication agent. This error typically arises due to issues with SSH key management and the authenticat
3 min read
How To Fix âgit authentication failedâ Error?
The "git authentication failed" error is a common issue that developers encounter when trying to interact with remote Git repositories, such as when pushing or pulling code from GitHub or GitLab. This error occurs when Git fails to authenticate the user while attempting to connect to a remote reposi
3 min read
How to Fix Git Error: 'failed to push some refs to remote'?
When working with Git, you might encounter the error message: "failed to push some refs to remote." This error typically occurs when your local repository is out of sync with the remote repository. This article will guide you through the steps to resolve this issue and successfully push your changes
3 min read
How to authenticate firebase with GitHub in ReactJS ?
The following approach covers how to authenticate firebase with GitHub in react. We have used the firebase module to achieve so. Creating React Application And Installing Module: Step 1: Create a React app using the following command: npx create-react-app gfgappStep 2: After creating your project fo
3 min read
How to find the Username and Password in PhpMyAdmin in Windows ?
In this article, we will see how to find the Username & Password of PhpMyAdmin in Windows. PhpMyAdmin is a free and open-source administration database management tool for MySQL and MariaDB. Sometimes, we forget the username and password that we set during registration. As the problem is without
2 min read
How to Fix GitHub Error: Authentication Failed from the Command Line ?
GitHub is a widely used platform for version control and collaborative development. However, encountering authentication errors can impede your workflow. One common issue is the "Authentication Failed" error, which occurs when your credentials are not properly recognized. This article will guide you
3 min read
How to Fix Git Error "Unable to create '/path/my_project/.git/index.lock'"?
The Git error "Unable to create '/path/my_project/.git/index.lock'" typically occurs when Git is unable to create or write to the index.lock file. This file is used to prevent simultaneous processes from modifying the repository, which could lead to corruption. Table of Content Remove the Lock File
2 min read