Git push results in "Authentication Failed"

1,473,821

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:

  1. Click Start
  2. Type: Credential Manager (on Windows 10, this is under "StartSettings". Then search for "Credential Manager")
  3. See the Windows Credentials Manager shortcut and double-click it to open the application.
  4. Once the application is open, click on the Windows Credentials tab.
  5. Locate the credentials that you want to remove/update. They will start with "git:" and might begin with "ada:"
  6. Click on the credential entry. It will open a details view of the entry.
  7. Click Edit or Remove as required and confirm.
  8. Lather, rinse, repeat as necessary.

Enter image description here

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:

  1. Run Git Bash

  2. Point to the repository directory

  3. Run git config --global credential.helper wincred

Share:
1,473,821
zkirkland
Author by

zkirkland

Updated on July 08, 2022

Comments

  • zkirkland
    zkirkland almost 2 years

    I have been using GitHub for a little while, and I have been fine with git add, git commit, and git 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 did git 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
    VonC over 10 years
    Indeed. +1. I present PAT here stackoverflow.com/a/19223896/6309 and detail the process there: stackoverflow.com/a/18607931/6309
  • John Nagle
    John Nagle over 9 years
    Not putting "www" on "github.com" works. Since that matters, Github should fix their site so you can't clone using "www".
  • leymannx
    leymannx over 9 years
    Switching from HTTPS to SSH solved the problem for me.
  • Admin
    Admin about 9 years
    Thank you : ) My url was missing the .git, and this comment got me to take a look at it and figure it out.
  • R11G
    R11G almost 9 years
    I needed to freshly generate my rsa keys for normal Git operations to work after enabling 2FA.
  • Darius Miliauskas
    Darius Miliauskas almost 9 years
    I didn't need to remove from config file this entry: askpass = /bin/echo.
  • James Wierzba
    James Wierzba over 8 years
    You switched from https to ssh
  • pourmesomecode
    pourmesomecode over 8 years
    Thank 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
    mailmindlin over 8 years
    you can also do git remote add origin https://username:[email protected]/username/repo.git to store your personal access token.
  • Walter Roman
    Walter Roman about 8 years
    I 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
    Ian W almost 8 years
    Took 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
    nha over 7 years
    It works! However I am a bit surprised that my ssh key was not being picked up.
  • Ellen Spertus
    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
    user5359531 almost 7 years
    For 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
    amarax almost 7 years
    Be careful with this command it will replace the real path to your credential helper with simply "wincred" which apparently not what you need.
  • BMW
    BMW over 6 years
    this works, which my environment need be https only
  • Neil
    Neil over 6 years
    Thanks @user5359531 - switching to ssh worked for me help.github.com/articles/…
  • Jonny
    Jonny over 6 years
    Documentation is here: help.github.com/articles/…
  • Omar
    Omar over 6 years
    I 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 with git config credential.helper store.
  • Hoque MD Zahidul
    Hoque MD Zahidul about 6 years
    I don't find this type of solution. I have re installed the git
  • manatlan
    manatlan about 6 years
    Fixed my trouble too (git was installed, just reinstalled it wich unchecking this : and it's ok !)
  • Toni Gamez
    Toni Gamez almost 6 years
    In my case it is not in "Windows Credentials" but is on "Generic Credentials". Remove the credential do the trick.
  • Andrew
    Andrew almost 6 years
    updated the remote from https to ssh in the steps to this solution and it worked perfectly. Thanks!
  • Stamp
    Stamp almost 6 years
    The 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
    Michel almost 6 years
    Certainly a lot easier than most answers. (And changing passwords should be the most common reason to get an authentication error ;-) )
  • Sufiyan Ansari
    Sufiyan Ansari over 5 years
    You can open the above window by (windows + R) -> "control /name Microsoft.CredentialManager"
  • Thomas Weller
    Thomas Weller over 5 years
    This answer does not explain what to do in case two-factor authentication is not enabled (which it isn't by default).
  • Ajay Chebbi
    Ajay Chebbi over 5 years
    if you are experiencing this on a existing clone - then just do a git push -u
  • Robin Macharg
    Robin Macharg over 5 years
    On a Mac, after answering the web capcha, this worked for me: git config --global credential.helper osxkeychain
  • doptrois
    doptrois almost 5 years
    I had to check "Use the native Windows Secure Channel library" too. It isn't checked by default.
  • improbable
    improbable over 4 years
    They 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
    Marques over 4 years
    The 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
    shary.sharath over 4 years
    My 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
    John Humphreys over 4 years
    This saved me when working with GitLab (when pretty much nothing else helped). Thanks!
  • Michael M
    Michael M over 4 years
    Fantastic 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
    Sam over 4 years
    I had never heard of this windows credentials manager.... Thanks !
  • Jchenna
    Jchenna over 4 years
    I 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
    MattE about 4 years
    Yes, that was the issue for me...needed to update the password to access TFS
  • Daniel Dror
    Daniel Dror about 4 years
    It 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
    devinbost almost 4 years
    This works great on Mac after a password expiration.
  • Dino
    Dino almost 4 years
    What happens if we want multiple users to do that? git remote add origin will not work as there can only be one oriigin
  • Îsh
    Îsh over 3 years
    Thank you Although the Edit did not fix it. I had to remove the entry under Generic Credentials and then issuing git clone on git cmd app prompted to enter user crendentials.
  • Atif AbbAsi
    Atif AbbAsi over 3 years
    You can open the above window by (windows + R) -> "control /name Microsoft.CredentialManager"
  • Gajraj Singh Chouhan
    Gajraj Singh Chouhan over 3 years
    anyway to automate the method @mailmindlin posted ? thanks.
  • DryLabRebel
    DryLabRebel over 3 years
    This 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
    Galih indra about 3 years
    Reinstalling 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
    Abhishek P about 3 years
    It 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
    stevec about 3 years
    Simplest and fastest fix IMO.
  • Ansjovis86
    Ansjovis86 almost 3 years
    And the token will be remembered for future pushes!
  • Alexey Larionov
    Alexey Larionov almost 3 years
    Having incorrect URL was indeed my issue, I mistakenly changed https:// to git://, while I needed [email protected]:user.repo.git. Strange that git didn't report the issue somehow, just silent hanging
  • VonC
    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
    Eng.Fouad almost 3 years
    I 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
    quantumferret almost 3 years
    You'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
    Przemek Pobuta almost 3 years
    I deleted my credentials from Windows Credential Manager and this command triggered the login dialog. Thanks!
  • essential
    essential over 2 years
    I 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
    Thiago Gouvea over 2 years
    What does option -T do in ssh? And why is it not listed here ssh.com/academy/ssh/command#ssh-command-line-options?
  • Alpesh Patil
    Alpesh Patil over 2 years
    The -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
    Venky over 2 years
    You saved my time! Thanks! This worked for me.
  • Cyber Knight
    Cyber Knight over 2 years
    This should be the selected answer.
  • Thorvald
    Thorvald over 2 years
    Having 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
    cmcodes over 2 years
    Now, I am getting a new error: Git: Host key verification failed.
  • Arjuna Deva
    Arjuna Deva over 2 years
    Thanks, same issue here. Luckily I found your post right away
  • Peter Mortensen
    Peter Mortensen over 2 years
    This answer is plagiarised at GitHub by John Mifsud. There isn't any attribution whatsoever.
  • Peter Mortensen
    Peter Mortensen over 2 years
    In 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
    Peter Mortensen over 2 years
    This is an exact duplicate of what user Sherlock posted more than a year prior and deleted 3 minutes before this answer was posted.
  • VinjaNinja
    VinjaNinja over 2 years
    Perfect! 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
    pete over 2 years
    So eveyrone who collaborates need you to generate a personal access token every time they want to commit or clone?
  • Salim Mazari Boufares
    Salim Mazari Boufares about 2 years
    This 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
    glhrmv about 2 years
    I 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
    Ingo about 2 years
    I don't have a Credentials Manager under User Accounts. I am running Manjaro.
  • Maf
    Maf about 2 years
    Are you sure that you added the public key to the agent?
  • elano7
    elano7 about 2 years
    Best answer. Very easy solution.
  • malifa
    malifa almost 2 years
    sometimes, 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!