Git push results in "Authentication Failed"
Solution 1
If you enabled two-factor authentication in your GitHub account you won't be able to push via HTTPS using your accounts password. Instead you need to generate a personal access token. This can be done in the application settings of your GitHub account. Using this token as your password should allow you to push to your remote repository via HTTPS. Use your username as usual.
Creating a personal access token
You may also need to update the origin for your repository if it is set to HTTPS. Do this to switch to SSH:
git remote -v
git remote set-url origin [email protected]:USERNAME/REPONAME.git
Solution 2
On Windows, try the following steps to edit or remove the saved credentials:
- Click Start
- Type: Credential Manager (on Windows 10, this is under "Start → Settings". Then search for "Credential Manager")
- See the Windows Credentials Manager shortcut and double-click it to open the application.
- Once the application is open, click on the Windows Credentials tab.
- Locate the credentials that you want to remove/update. They will start with "git:" and might begin with "ada:"
- Click on the credential entry. It will open a details view of the entry.
- Click Edit or Remove as required and confirm.
- Lather, rinse, repeat as necessary.
Solution 3
It happens if you change your login or password of git service account (Git). You need to change it in Windows Credentials Manager too. type "Credential Manager" in Windows Search menu open it.
Windows Credentials Manager->Windows Credential and under Generic Credentials edit your git password.
Solution 4
Maybe you have changed the password recently for you Git account.
You could try the git push
line with the -u
option:
git push -u origin branch_name_that_you_want_to_push
After executing the above command, it will ask for a password. Provide your updated password.
Solution 5
On Windows, this worked for me, and it also remembers my credentials:
-
Run Git Bash
-
Point to the repository directory
-
Run
git config --global credential.helper wincred
zkirkland
Updated on July 08, 2022Comments
-
zkirkland almost 2 years
I have been using GitHub for a little while, and I have been fine with
git add
,git commit
, andgit push
, so far without any problems. Suddenly I am having an error that says:fatal: Authentication Failed
In the terminal I cloned a repository, worked on a file and then I used
git add
to add the file to the commit log and when I didgit commit
, it worked fine. Finally,git push
asks for username and password. I put those in correctly and every time I do this, it says the same error.What is the cause of this problem and how can I fix it?
The contents of
.git/config
are:[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = http://www.github.com/######/Random-Python-Tests fetch = +refs/heads/*:refs/remotes/origin/* [branch "master"] remote = origin merge = refs/heads/master [user] name = ##### email = ############
-
VonC over 10 yearsIndeed. +1. I present PAT here stackoverflow.com/a/19223896/6309 and detail the process there: stackoverflow.com/a/18607931/6309
-
John Nagle over 9 yearsNot putting "www" on "github.com" works. Since that matters, Github should fix their site so you can't clone using "www".
-
leymannx over 9 yearsSwitching from HTTPS to SSH solved the problem for me.
-
Admin about 9 yearsThank you : ) My url was missing the .git, and this comment got me to take a look at it and figure it out.
-
R11G almost 9 yearsI needed to freshly generate my rsa keys for normal Git operations to work after enabling 2FA.
-
Darius Miliauskas almost 9 yearsI didn't need to remove from config file this entry:
askpass = /bin/echo
. -
James Wierzba over 8 yearsYou switched from https to ssh
-
pourmesomecode over 8 yearsThank you! Just had this error and this helped, just to point out. Once you've created your personal access token you copy that then when your pushing the repo, it'll ask for your username and password. Paste the Access Token in the Password
-
mailmindlin over 8 yearsyou can also do
git remote add origin https://username:[email protected]/username/repo.git
to store your personal access token. -
Walter Roman about 8 yearsI had enabled 2-factor authentication for my GH account and switching the remote url to SSH from HTTPS resolved the "authentication failed" issue for me. Makes sense. Thanks!
-
Ian W almost 8 yearsTook me a while to find out what that does -- it uses the Credential Manager in the Windows Control Panel. To stop using it:
git config –global credential.helper unset
Source, and more details in this answer. -
nha over 7 yearsIt works! However I am a bit surprised that my ssh key was not being picked up.
-
Ellen Spertus about 7 years@IanW Do you mean
git config --global --unset credential.helper
? That's what worked for me in Git Bash. -
user5359531 almost 7 yearsFor me, all I had to do was enable SSH authentication from my local machine on my GitHub account, and then switch to the ssh git remote address; help.github.com/articles/changing-a-remote-s-url
-
amarax almost 7 yearsBe careful with this command it will replace the real path to your credential helper with simply "wincred" which apparently not what you need.
-
BMW over 6 yearsthis works, which my environment need be
https
only -
Neil over 6 yearsThanks @user5359531 - switching to ssh worked for me help.github.com/articles/…
-
Jonny over 6 yearsDocumentation is here: help.github.com/articles/…
-
Omar over 6 yearsI ran this command to find out it's not what i wanted, the proper way to unset is
git config --global --unset credential.helper
. Ultimately, I restored my correct setting withgit config credential.helper store
. -
Hoque MD Zahidul about 6 yearsI don't find this type of solution. I have re installed the git
-
manatlan about 6 yearsFixed my trouble too (git was installed, just reinstalled it wich unchecking this : and it's ok !)
-
Toni Gamez almost 6 yearsIn my case it is not in "Windows Credentials" but is on "Generic Credentials". Remove the credential do the trick.
-
Andrew almost 6 yearsupdated the remote from https to ssh in the steps to this solution and it worked perfectly. Thanks!
-
Stamp almost 6 yearsThe mistake I made was thinking the Personal Access Token was the friendly name. After regenerating the PAT I realised it was actually a GUID - Doh!
-
Michel almost 6 yearsCertainly a lot easier than most answers. (And changing passwords should be the most common reason to get an authentication error ;-) )
-
Sufiyan Ansari over 5 yearsYou can open the above window by (windows + R) -> "control /name Microsoft.CredentialManager"
-
Thomas Weller over 5 yearsThis answer does not explain what to do in case two-factor authentication is not enabled (which it isn't by default).
-
Ajay Chebbi over 5 yearsif you are experiencing this on a existing clone - then just do a
git push -u
-
Robin Macharg over 5 yearsOn a Mac, after answering the web capcha, this worked for me:
git config --global credential.helper osxkeychain
-
doptrois almost 5 yearsI had to check "Use the native Windows Secure Channel library" too. It isn't checked by default.
-
improbable over 4 yearsThey must notify people who have enabled TFA about this! How am I supposed to know that without intentionally scrolling to Github Help, what I don't usually do even when something happens.
-
Marques over 4 yearsThe credentials may be there, but without 'git:' in front of it. That is not going to work. It needs to start with 'git:'
-
shary.sharath over 4 yearsMy employer set windows authentication to Git Hub, so every time I changed my windows credentials I had to update it for source control. Your answer worked.
-
John Humphreys over 4 yearsThis saved me when working with GitLab (when pretty much nothing else helped). Thanks!
-
Michael M over 4 yearsFantastic answer. We maintain an internal BitBucket repository, where each of our account credentials are authenticated to our organization. Recently all of my repositories became unavailable for pushing code changes. While I had been able to change credentials on a case per case basis, I really did not want to do this for every project. @Pradeep's approach allowed me to solve the underlying cause, which was more than simply a password change. Our organization recently changed the name of the internal domain, so by editing the credentials centrally, I was able to fix all of my projects.
-
Sam over 4 yearsI had never heard of this windows credentials manager.... Thanks !
-
Jchenna over 4 yearsI gave wrong credentials when Git prompted me for user id and password while pushing new files to remote repository. When I ran push command again git did not prompt me for credentials but instead it was only throwing authentication failed error. I realised after reading this answer that git uses credentials stored in credential manager and that should be the reason git does not prompt for password everytime we push into remote respository. I deleted the git password in credential manager after which git again prompted me for user id and password.
-
MattE about 4 yearsYes, that was the issue for me...needed to update the password to access TFS
-
Daniel Dror about 4 yearsIt works for me as well. This is not magic, it is because I have stored configuration for ssh access (with a public key configured), which are not picked up for https access (which is user/pass + MFA).
-
devinbost almost 4 yearsThis works great on Mac after a password expiration.
-
Dino almost 4 yearsWhat happens if we want multiple users to do that?
git remote add origin
will not work as there can only be one oriigin -
Îsh over 3 yearsThank you Although the Edit did not fix it. I had to remove the entry under
Generic Credentials
and then issuinggit clone
on git cmd app prompted to enter user crendentials. -
Atif AbbAsi over 3 yearsYou can open the above window by (windows + R) -> "control /name Microsoft.CredentialManager"
-
Gajraj Singh Chouhan over 3 yearsanyway to automate the method @mailmindlin posted ? thanks.
-
DryLabRebel over 3 yearsThis also solved the problem for me. After I switched to two-factor authentication, I set up a public key in my GitHub account.
-
Galih indra about 3 yearsReinstalling git works fine for me. Download the newest installer. Enable newest feature of git credential manager during installation. Before you push the repo. A window will pop-up and you will be able to login via browser.
-
Abhishek P about 3 yearsIt asks for username and password when you do 'git push' again atleast in my case, enter your credentials and you are good to go
-
stevec about 3 yearsSimplest and fastest fix IMO.
-
Ansjovis86 almost 3 yearsAnd the token will be remembered for future pushes!
-
Alexey Larionov almost 3 yearsHaving incorrect URL was indeed my issue, I mistakenly changed
https://
togit://
, while I needed[email protected]:user.repo.git
. Strange that git didn't report the issue somehow, just silent hanging -
VonC almost 3 years@AlexeyLarionov Since
git://
is a valid (albeit obsolete) protocol, it simply tried and use it, waiting for a remote server to listen on port 9418. -
Eng.Fouad almost 3 yearsI had to add new entry into Windows Credential Manager (generic credentials) manually despite there was an existing entry already. The URL looks like:
git:https://192.168.1.10
(TFS Server). -
quantumferret almost 3 yearsYou're a lifesaver, I was just about to give up and send an email to Support when I saw this answer, since the same thing was happening to me (no clue why windows credentials didn't update automatically like the last time I had to change my computer password, but oh well).
-
Przemek Pobuta almost 3 yearsI deleted my credentials from Windows Credential Manager and this command triggered the login dialog. Thanks!
-
essential over 2 yearsI did that and it still does not prompt for the credentials. I also removed the user credentials from Windows password manager. I went through almost all answers here, but didn't help any suggestions? it only works when I put credentials in the address e.g. git push https://<user>:<pwd>@<bitbucketaddress>
-
Thiago Gouvea over 2 yearsWhat does option
-T
do inssh
? And why is it not listed here ssh.com/academy/ssh/command#ssh-command-line-options? -
Alpesh Patil over 2 yearsThe
-T
option will disable pseudo terminal allocation while connecting to a Git remote server over SSH. Git server will respond to SSH request having-T
option. -
Venky over 2 yearsYou saved my time! Thanks! This worked for me.
-
Cyber Knight over 2 yearsThis should be the selected answer.
-
Thorvald over 2 yearsHaving the same issues, VScode on ubuntu 20.04. Did you find a solution to make the integrated terminal to work? (I'm using bash)
-
cmcodes over 2 yearsNow, I am getting a new error:
Git: Host key verification failed.
-
Arjuna Deva over 2 yearsThanks, same issue here. Luckily I found your post right away
-
Peter Mortensen over 2 yearsThis answer is plagiarised at GitHub by John Mifsud. There isn't any attribution whatsoever.
-
Peter Mortensen over 2 yearsIn what context? Where does it go? Is all or part of it literal or not? The configuration file entries in the question has the form
setting = value
(=
is literal). -
Peter Mortensen over 2 yearsThis is an exact duplicate of what user Sherlock posted more than a year prior and deleted 3 minutes before this answer was posted.
-
VinjaNinja over 2 yearsPerfect! This is a quick and short solution, worked for me in an instant for bitbucket. If this issue repeats after editing the password, remove the logon. New creds for git are prompted when doing a git operation like pull or push.
-
pete over 2 yearsSo eveyrone who collaborates need you to generate a personal access token every time they want to commit or clone?
-
Salim Mazari Boufares about 2 yearsThis solution is no longer valid: Git will notify with "Support for password authentication was removed on August 13, 2021. Please use a personal access token instead." and recommend to follow this link: github.blog/…
-
glhrmv about 2 yearsI feel compelled to comment because I was starting to lose hope, none of these answers were working for me, but those last two commands ensured git asked me for my new credentials. Thank you.
-
Ingo about 2 yearsI don't have a Credentials Manager under User Accounts. I am running Manjaro.
-
Maf about 2 yearsAre you sure that you added the public key to the agent?
-
elano7 about 2 yearsBest answer. Very easy solution.
-
malifa almost 2 yearssometimes, the git entry doesn't show up in "windows credential manager". It didn't show up for me in my win11 laptop. So, I went and edited my %userprofile%\.gitconfig file and saved it. then windows prompted me for the password when I executed "git pull" command. This time, after I entered the correct new password, I saw that "windows credential manager" had created an entry for git!