943
votes

I have been using Github for a little while and I have been fine with git add, git commit, and git push so far with no 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.

Does anyone have any idea what the cause of this problem is and how I can 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 = ############
30
what is your username on github and what are the contents of .git/config?mnagel
add it to the question, comments dont cope with long textmnagel
Yeah sorry, I started the comment out of habit then changed it.zkirkland
Your url doesn't look right. I think it should start with https://, not http://.John Szakmeister
Changed to https... didn't work.zkirkland

30 Answers

1513
votes

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.

https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/

You may also need to update the origin for your repository if set to https:

git remote -v 
git remote remove origin 
git remote add origin [email protected]:user/repo.git  
850
votes

Try the following steps to Edit or Remove the saved credentials:

  1. Click Start
  2. Type: Credential Manager (On Windows 10, this is under "Start->Settings". Then search for "Credential Manager")
  3. See the Windows Credentials Manager shortcut and double-click it to open the application.
  4. Once the app 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. Wash, rinse, repeat as necessary.

enter image description here

115
votes

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.

104
votes

May you have changed password recently for you git account You could try the git push with -u option

git push -u origin branch_name_that_you_want_to_push

After executing above command it will ask for password provide your updated password

Hope it may help you

95
votes

This worked for me, and it also remembers my credentials:

  1. Run gitbash

  2. Point to the repo directory

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

73
votes

First, you can make sure to use the proper url:

git remote set-url origin https://github.com/zkirkland/Random-Python-Tests.git

Then, if it was working before, and if it wasn't asking for you username, it must be because you had stored your credentials (login/password) in a $HOME/.netrc file, as explained here. You can double-check those settings, and make sure that your proxy, if you have one, hasn't changed.

If that still doesn't work, you can switch to an ssh url:

git remote set-url origin [email protected]:zkirkland/Random-Python-Tests.git

But that means you have published your ssh public key in your Account settings.

62
votes

Basically my credential was expired, and I was facing above issue.

Following 2 command helped me:

git config --global --unset credential.helper

git config credential.helper store

It will asks you for credentials next time when you try to push.

Follow below guidelines for more details for secured and unsecured storage of user name and passwords:

https://git-scm.com/docs/git-credential-store

https://git-scm.com/docs/git-credential-cache

36
votes

If you found authentication error problem when you entered correct password and username it's git problem. To solves this problem when you are installing the git in your machine uncheck the enable git credential managerenter image description here

29
votes

I think that for some reason GitHub is expecting the URL to NOT have subdomain www. When I use (for example)

git remote set-url origin https://www.github.com/name/repo.git

it gives the following messages:

remote: Anonymous access to name/repo.git denied
fatal: Authentication failed for https://www.github.com/name/repo.git

However, if I use

git remote set-url origin https://github.com/name/repo.git

it works perfectly fine. Doesn't make too much sense to me... but I guess remember not to put www in the remote URL for GitHub repositories.

Also notice the clone URLs provided on the GitHub repository webpage doesn't include the www.

29
votes

Hi, I was getting the same error i tried all the solutions whichever mentioned in this page, but didn't work. Finally, i found the solution, So thought of posting it. Please correct me if i am wrong anywhere. These kinds of error comes if sometimes your system password has changed recently anytime. It will try to validate from old password. So, Follow these steps:

  1. Go to control panel
  2. Click on User accounts
  3. Under Credentials manager
  4. Go to Manage windows credentials
  5. Go to Generic credentials
  6. Expand git server tab
  7. click on Remove from vault

    • Also you can click edit and change your password stored here directly.
13
votes

I'm not really sure what I did to get this error, but doing:

git remote set-url origin https://...

didn't work for me. However:

git remote set-url origin [email protected]:user/repo

somehow worked.

12
votes

I've ran into "$ git fetch fatal: Authentication failed for 'http://...." after my windows password has expired and was changed. Multiple fetches, reboot and even reinstall of git with windows credential manager didn't help.

Surprisingly the right answer somewhere here in comments but not in answers (and some of them are really weird!). You need to go to Control panel -> Credential Manager / Windows Credentials and update you password for git:http://yourrepoaddress

10
votes

In my case, I recently changed my windows password and I have SSH key configured for git related actions (pull, push, fetch etc.,), after I encountered the "fatal: Authentication failed" error, I updated my password in the windows credential manager (Control Panel\User Accounts\Credential Manager)for all items starting with git:..., and tried again, worked this time!

10
votes

I was adding to Bitbucket linked with Git and had to remove the stored keys, as this was causing the fatal error.

To resolve, I opened the command prompt and ran

 rundll32.exe keymgr.dll, KRShowKeyMgr

I removed the key that was responsible for signing in and next time I pushed the files to the repo, I was prompted for credentials and entered the correct ones, resulting in a successful push.

10
votes

Before you try everything above, try to git push again, yes it works on me.

8
votes

I had the same problem. I set url in that way:

git remote set-url origin https://github.com/zkirkland/Random-Python-Tests.git

I also removed from config file this entry: askpass = /bin/echo. Then "git push" asked me for username and password and this time it worked.

4
votes

If you are on windows and trying to push to a windows server which has domain users working as repository users (TFS), try getting into TFS URL (i.e. http:\\tfs) with IE. enter your domain account credentials and let the page appear.

CAUTION only use INTERNET EXPLORER! other browsers wont change your system credentials.

Now go to git bash and change your remote user for the repository like below :

git config user.name "domainName\userName"

And done, now you can push!

4
votes

If you have enabled the two-factor authentication on your Github account, then sign in to your GitHub account and go to: https://github.com/settings/tokens/new to generate new access token, copy that token and paste as a password for authentication in terminal.

2
votes

I tried the token verification method and got it to work ~3 times and wasted around 2 hours of time for that. For some reason it does not work very well for our company.

My solution was to change the authentication method from HTTPS to SSH. Here is a Github guide (https://help.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent).

After you have created the SSH key, remember to change the SSH address origin:

git remote add origin [email protected]:user/repo.git
2
votes

Got the above error message when I updated my computer password. Reset my git credentials using the following steps:

Go to Control Panel > User Accounts > Credential Manager > Windows Credentials. You will see Git credentials in the list (e.g. git:https://). Click on it, update the password, and execute git pull/push command from your Git bash and it won't throw any more error messages.

1
votes

For me, I forgot that I had changed the password on Github.com, and my keychain for shell authentication never updated to that new password. Deleting everything git from my keychain and then re-running the git request helped solve the issue, prompting me again for the new password.

1
votes

Just to chime in here, what fixed the issue for me was I simply canceled out of the initial prompt, the ssh one opened up with my bitbucket account, I entered the password there and everything worked as expected.

1
votes

I was facing the same issue on windows. Most of the time I normally face the issue due to using multiple git accounts. If you are on windows, please do open the terminal as an administrator and try running the commands again. Make sure that you have the administrator access rights.

1
votes

The same error (Windows, Git Bash command line). Using https which should prompt for login credentials but instead errors:

$ git pull origin master
fatal: Authentication failed for 'https://github.com/frmbelz/my_git_project.git'
$ git config -l
...
credential.helper=manager
...

$ git config --global --unset credential.helper
$ git config --system --unset credential.helper

git pull now prompted for username/password prompts.

0
votes

I also ran into the error (that's why I am landed here), but none of the suggestions worked for me. This was my very first time I try to deploy local Git to azure. When I got this error, I reset my credentials (by clicking the link in Azure) after a few tries. The problem is that at this point it tells me my user name is already taken, so I also changed my user name to another one. In the end, I manually deleted the .git folder on my local drive, and redeployed it without problem.

0
votes

Problem Statement: "git fatal authentication failed". I am using bitbucket.

Solution: I simply deleted the user from using access management of bitbucket and then added the same user. The .gitconfig file is simple

[user]
    name = BlaBla
    email = [email protected]

[push]
    default = simple
0
votes

with correct credentials if the problem prevails

if your using androidstudio 2.1 beta then its bug , upgrade to beta 2 (3 mb update file) , this worked for me

0
votes

Make sure you have WRITE permission to push.

read ***write*** admin 
0
votes

Make sure that your ssh key is added to your current ssh session.

  1. Copy the output of cat ~/.ssh/id_rsa.pub to your GitHub settings under SSH and GPG keys.

  2. Update your current ssh session with ssh-add ~/.ssh/id_rsa.pub

I am using Windows Powershell with Openssh installed.