1181

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 = ############
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
zkirkland
  • 12,175
  • 3
  • 16
  • 18

47 Answers47

1754

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 git@github.com:USERNAME/REPONAME.git
basZero
  • 4,129
  • 9
  • 51
  • 89
rc0r
  • 18,631
  • 1
  • 16
  • 20
  • 11
    Indeed. +1. I present PAT here http://stackoverflow.com/a/19223896/6309 and detail the process there: http://stackoverflow.com/a/18607931/6309 – VonC Jan 09 '14 at 18:54
  • 4
    I needed to freshly generate my rsa keys for normal Git operations to work after enabling 2FA. – R11G Jul 01 '15 at 13:42
  • 8
    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 – pourmesomecode Oct 21 '15 at 14:18
  • 191
    you can also do `git remote add origin https://username:access-token@github.com/username/repo.git` to store your personal access token. – mailmindlin Feb 04 '16 at 00:48
  • It works! However I am a bit surprised that my ssh key was not being picked up. – nha Sep 10 '16 at 16:02
  • 7
    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; https://help.github.com/articles/changing-a-remote-s-url/ – user5359531 Jun 23 '17 at 02:52
  • Thanks @user5359531 - switching to ssh worked for me https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/ – Neil Aug 24 '17 at 15:59
  • Documentation is here: https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/ – Jonny Sep 27 '17 at 01:17
  • updated the remote from https to ssh in the steps to this solution and it worked perfectly. Thanks! – Andrew Jul 10 '18 at 18:34
  • 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! –  Jul 20 '18 at 13:56
  • This answer does not explain what to do in case two-factor authentication is not enabled (which it isn't by default). – Thomas Weller Dec 01 '18 at 21:54
  • 1
    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. – improbable Aug 26 '19 at 13:25
  • What happens if we want multiple users to do that? ``git remote add origin`` will not work as there can only be one oriigin – Dino Aug 12 '20 at 16:35
  • anyway to automate the method @mailmindlin posted ? thanks. – Gajraj Singh Chouhan Jan 11 '21 at 17:45
  • And the token will be remembered for future pushes! – Ansjovis86 May 20 '21 at 17:58
  • Now, I am getting a new error: `Git: Host key verification failed.` – cmcodes Nov 15 '21 at 04:32
  • 1
    This answer is plagiarised [at GitHub](https://gist.github.com/imabuddha/e3e40f8df6b292fd8b2df9c3105b71e9) by John Mifsud. There isn't any attribution whatsoever. – Peter Mortensen Dec 11 '21 at 19:47
  • So eveyrone who collaborates need you to generate a personal access token every time they want to commit or clone? – pete Jan 21 '22 at 12:04
  • only solution when there is credentials in he remote url! thanks. – myuce Nov 16 '22 at 13:02
  • 2022/23 suggestion — [Git Credential Manager](https://github.com/GitCredentialManager/git-credential-manager/blob/main/README.md). [Github docs](https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git#git-credential-manager) – Jeff Spicoli Dec 01 '22 at 20:21
  • It worked for me! – Pramod Shinde Jul 24 '23 at 19:21
999

On Windows, try the below 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. Later rinse and repeat as necessary.

Enter image description here

Pradeep
  • 12,309
  • 3
  • 20
  • 25
  • 6
    In my case it is not in "Windows Credentials" but is on "Generic Credentials". Remove the credential do the trick. – Toni Gamez Jun 06 '18 at 08:34
  • 17
    You can open the above window by (windows + R) -> "control /name Microsoft.CredentialManager" – Sufiyan Ansari Nov 15 '18 at 12:00
  • The credentials may be there, but without 'git:' in front of it. That is not going to work. It needs to start with 'git:' – Marques Oct 08 '19 at 14:13
  • 4
    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. – shary.sharath Oct 14 '19 at 09:32
  • 3
    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. – Michael M Nov 21 '19 at 17:03
  • Yes, that was the issue for me...needed to update the password to access TFS – MattE Feb 18 '20 at 13:13
  • 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. – Îsh Nov 20 '20 at 21:06
  • 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). – Eng.Fouad Jun 28 '21 at 10:47
  • 2
    This should be the selected answer. – Cyber Knight Oct 20 '21 at 13:07
  • 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! – anjanb Jun 07 '22 at 05:42
  • This definitely should be the selected answer. – Rafael Amaral Jan 18 '23 at 20:26
175

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Users9949
  • 1,819
  • 1
  • 12
  • 11
  • this works, which my environment need be `https` only – BMW Aug 24 '17 at 02:12
  • 12
    Certainly a lot easier than most answers. (And changing passwords should be the most common reason to get an authentication error ;-) ) – Michel Aug 11 '18 at 10:00
  • 2
    if you are experiencing this on a existing clone - then just do a `git push -u ` – Ajay Chebbi Jan 31 '19 at 12:42
  • I deleted my credentials from Windows Credential Manager and this command triggered the login dialog. Thanks! – Przemek Pobuta Aug 11 '21 at 06:01
  • 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: https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ – Salim Mazari Boufares Feb 18 '22 at 15:12
  • Best answer. Very easy solution. – elano7 May 01 '22 at 00:56
136

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.

Atif AbbAsi
  • 5,633
  • 7
  • 26
  • 47
  • 10
    This saved me when working with GitLab (when pretty much nothing else helped). Thanks! – John Humphreys Nov 03 '19 at 00:19
  • 5
    I had never heard of this windows credentials manager.... Thanks ! – Sam Dec 17 '19 at 09:08
  • 1
    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. – Jchenna Jan 09 '20 at 04:00
  • 1
    You can open the above window by (windows + R) -> "control /name Microsoft.CredentialManager" – Atif AbbAsi Dec 12 '20 at 21:09
  • 2
    Simplest and fastest fix IMO. – stevec Apr 22 '21 at 00:26
113

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Utukku
  • 1,315
  • 1
  • 10
  • 6
  • 23
    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](http://www.codewrecks.com/blog/index.php/2015/06/23/git-for-windows-getting-invalid-username-or-password-with-wincred/), and more details in [this answer](http://stackoverflow.com/questions/15381198/remove-credentials-from-git). – Ian W Jul 26 '16 at 12:32
  • 11
    @IanW Do you mean `git config --global --unset credential.helper`? That's what worked for me in Git Bash. – Ellen Spertus May 15 '17 at 17:51
  • 3
    Be careful with this command it will replace the real path to your credential helper with simply "wincred" which apparently not what you need. – amarax Jun 29 '17 at 10:31
  • 4
    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`. – Omar Nov 30 '17 at 01:52
  • On a Mac, after answering the web capcha, this worked for me: `git config --global credential.helper osxkeychain` – Robin Macharg Feb 06 '19 at 13:38
103

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

The following two commands helped me:

git config --global --unset credential.helper

git config credential.helper store

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

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jems
  • 1,059
  • 1
  • 7
  • 6
  • 2
    This works great on Mac after a password expiration. – devinbost Aug 11 '20 at 23:24
  • 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://:@ – essential Sep 24 '21 at 14:14
  • 1
    For me and Windows 10, it worked perfectly. – Karel Macek Oct 14 '22 at 07:30
  • This answer pointed me towards looking into my `.gitconfig` file, which is what I ended up needing to do. – zcoop98 Jun 12 '23 at 16:02
99

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 your 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.

Check the output of git config --global credential.helper.
And make sure the credentials are your GitHub user account, and a PAT (Personal Access token).

You can update your credentials using the Git credential helper, as in here.


If that still doesn't work, you can switch to an SSH URL:

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

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


For Visual Studio Code specifically, see also "git push: Missing or invalid credentials. fatal: Authentication failed for 'https://github.com/username/repo.git'"

You can unselect the setting git.terminalAuthentication to avoid the error message.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 14
    Switching from HTTPS to SSH solved the problem for me. – leymannx Jan 20 '15 at 11:49
  • 3
    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! – Walter Roman Feb 20 '16 at 18:02
  • 1
    This also solved the problem for me. After I switched to two-factor authentication, I set up a public key in my GitHub account. – DryLabRebel Jan 20 '21 at 19:30
  • 1
    Having incorrect URL was indeed my issue, I mistakenly changed `https://` to `git://`, while I needed `git@github.com:user.repo.git`. Strange that git didn't report the issue somehow, just silent hanging – Alexey S. Larionov Jun 02 '21 at 13:36
  • @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. – VonC Jun 02 '21 at 17:37
44

On Windows, if you found an authentication error problem when you entered the correct password and username, it's a Git problem. To solve this problem, when you are installing the Git in your machine, uncheck the Enable Git Credential Manager option.

Enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Hoque MD Zahidul
  • 10,560
  • 2
  • 37
  • 40
  • 1
    I don't find this type of solution. I have re installed the git – Hoque MD Zahidul Mar 14 '18 at 20:34
  • 1
    Fixed my trouble too (git was installed, just reinstalled it wich unchecking this : and it's ok !) – manatlan May 16 '18 at 09:49
  • 2
    I had to check "Use the native Windows Secure Channel library" too. It isn't checked by default. – doptrois Jul 05 '19 at 15:19
  • 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. – Galih indra Feb 18 '21 at 09:49
33

I was getting the same error. I tried all the solutions whichever mentioned in this page, but they didn't work. Finally, I found the solution.

These kinds of error comes if sometimes your system password has changed recently anytime. It will try to validate from the 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 the Git server tab
  7. Click on Remove from vault
  • Also, you can click Edit and change your password stored here directly.
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
xoxo
  • 1,248
  • 14
  • 19
  • This is an exact duplicate of what user [Sherlock](https://stackoverflow.com/users/8329844/sherlock) posted more than a year prior and deleted 3 ***minutes*** before this answer was posted. – Peter Mortensen Dec 11 '21 at 21:38
  • I don't have a Credentials Manager under User Accounts. I am running Manjaro. – Ingo Mar 28 '22 at 06:43
31

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.

Chei
  • 2,117
  • 3
  • 20
  • 33
Electo
  • 520
  • 5
  • 7
  • 5
    Not putting "www" on "github.com" works. Since that matters, Github should fix their site so you can't clone using "www". – John Nagle Nov 13 '14 at 02:36
  • 1
    Thank you : ) My url was missing the .git, and this comment got me to take a look at it and figure it out. –  Mar 27 '15 at 02:05
20

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

Justin Herrera
  • 526
  • 4
  • 11
16

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.

Vladislav Povorozniuc
  • 2,149
  • 25
  • 26
  • 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. – glhrmv Mar 02 '22 at 11:01
15

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 git@bitbucket.org:user/repo

somehow worked.

Kafeaulait
  • 664
  • 1
  • 6
  • 14
  • 7
    You switched from https to ssh – James Wierzba Sep 11 '15 at 17:24
  • 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). – Daniel Dror Mar 03 '20 at 08:43
14

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.

William Humphries
  • 541
  • 1
  • 10
  • 21
  • 1
    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. – VinjaNinja Jan 12 '22 at 15:34
13

I've ran into

git fetch

fatal: Authentication failed for 'http://...."

after my Windows password had expired and was changed. Multiple fetches, reboot and even reinstall of Git with Windows Credential Manager didn't help.

Surprisingly the right answer is somewhere here in comments, but not in answers (and some of them are really weird!).

You need to go to Control PanelCredential ManagerWindows Credentials and update you password for git:http://your_repository_address

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
amarax
  • 508
  • 5
  • 14
11

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!

Kiran Modini
  • 1,184
  • 8
  • 5
9

I had the same problem. I set the URL in this way:

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

I also removed this entry from the configuration file: askpass = /bin/echo.

Then "git push" asked me for username and password and this time it worked.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Bartosz
  • 93
  • 2
  • 5
6

If you have enabled the two-factor authentication on your GitHub account, then sign in to your GitHub account and go to

New personal access token

to generate a new access token, copy that token, and paste as a password for authentication in the terminal.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
RegarBoy
  • 3,228
  • 1
  • 23
  • 44
4

Just from your .config file change:

url = http://www.github.com/###user###/Random-Python-Tests

To:

url = http://###user###@github.com/###user###/Random-Python-Tests
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
ccamacho
  • 707
  • 8
  • 22
4

I started experiencing this issue on Visual Studio Code in Ubuntu 20.04 yesterday.

I did not make any changes to my GitHub credentials, neither did I change anything in the project, but I run any git command to communicate with my remote branch like:

git pull origin dev

I get the error below:

remote: Repository not found. fatal: Authentication failed for 'https://github.com/MyUsername/my-project.git/'

Here's what worked for me:

I tried recloning the project and then running the git pull command but it did not work.

git clone https://my-git-url

I tried setting my credentials again using the below commands but still no luck:

git config --global user.email "email@example.com"
git config --global user.name "John King"

I tried removing the remote repository and re-adding it using the below commands, but still no luck:

git remote remove origin
git remote add origin https://my-git-url

Finally, I decided to try using my default Ubuntu terminal and it worked fine. My big guess is that it's a bug from Visual Studio Code from the last update that was made some few hours before then (See the screenshot that shows that a Release was done on the same day that I was having the issue). I mean I set up Visual Studio Code using snap, so probably it might have been updated in the background a few hours before then.

enter image description here

Hopefully, they will get it fixed and git remote operations will be fine again.

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
3

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 the TFS URL (i.e. http:\\tfs) with Internet Explorer. Enter your domain account credentials and let the page appear.

Caution: Only use Internet Explorer! Other browsers won’t 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!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
AmiNadimi
  • 5,129
  • 3
  • 39
  • 55
3

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.

Marilynn
  • 71
  • 5
  • 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). – quantumferret Jul 09 '21 at 08:52
2

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 rerunning the Git request helped solve the issue, prompting me again for the new password.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
MMMdata
  • 817
  • 8
  • 19
2

If you are using SSH and cloned with HTTPS, this will not work.

Clone with SSH and then push and pulls should work as expected!

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
GoldenWest
  • 281
  • 2
  • 4
  • 16
2

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 git@github.com:user/repo.git
jeppoo1
  • 650
  • 1
  • 10
  • 23
2

I was getting below error when trying to push to github remote

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Solution SSH Keys were missing on github account

  1. Copy local public ssh keys from ~/.ssh directory

  2. Paste to Github > Settings > SSH and GPG Keys > New SSH Key

  3. Try ssh -T git@github.com This should output

    Hi xxxxx! You've successfully authenticated, but GitHub does not provide shell access.

Alpesh Patil
  • 1,672
  • 12
  • 15
  • What does option `-T` do in `ssh`? And why is it not listed here https://www.ssh.com/academy/ssh/command#ssh-command-line-options? – Thiago Gouvea Oct 08 '21 at 09:44
  • 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. – Alpesh Patil Oct 08 '21 at 11:19
2

the quick GUI way of doing is:

  1. Firstly generate an access token via create app access token.
  2. then goto sourceTree's Settings(placed under the close button of the Source tree)
  3. A prompt will appear named "Repository Settings".
  4. There add/edit your repository path with https://USER_NAME:ACCESS_TOKEN@bitbucket.org/REPO_NAME/PROJECT_NAME.git

or for github account

https://username:access-token@github.com/username/repo.git

Here the only change to mention is adding the additional accessToken generated by the above shared create app access token link into existing path url.

Muahmmad Tayyib
  • 689
  • 11
  • 28
  • In my case, I was using the password for DevOps login when Git request password after user has ben entered; I was wrong since I needed to enter password provided with the creation of Personal Access Token (PAT) - that password shows a warning that it must be copied, since won't be shown again -. In summary, provide Git credentials as user and pwd showed in that creation step. – Chesare Mar 22 '23 at 20:18
2

The question was asked way before Two-Factor Authentication was introduced by GitHub, however, many people are encountering this error ever since GitHub introduced 2FA.

GitHub asks for authentication every time you try to push, if you want to avoid getting prompted repeatedly, you should use github-cli which is very lightweight and you can install with apt, yum, dnf and pacman.

after installing github-cli,

  1. Type this command
gh auth login
  1. Select the account type to authenticate
  2. Select HTTPS or SSH (as desired)
  3. Login with a web browser or authenticate with access tokens as per your ease.

Access tokens can be generated from GitHub > Settings > Developer-settings > Generate Access token, copy the token, and paste it into the terminal, It is a one-time code so ensure that you do not lose the code before authenticating it on the terminal

2

In Sourcetree Go to Tools -> Options -> Authentication

On Your Email Id click on Edit and click on Refresh OAuth Token.

1

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Trevor Hart
  • 993
  • 7
  • 26
1

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Muema
  • 190
  • 2
  • 13
0

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 tried to deploy a local Git repository 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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
newman
  • 6,841
  • 21
  • 79
  • 126
0

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

Solution:

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

[user]
    name = BlaBla
    email = blabla@gmail.com

[push]
    default = simple
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
J4cK
  • 30,459
  • 8
  • 42
  • 54
0

With correct credentials if the problem prevails:

If you’re using Android Studio 2.1 beta then it’s a bug. Upgrade to beta 2 (3 MB update file). This worked for me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
geniushkg
  • 706
  • 9
  • 21
0

Make sure you have write permission to push.

read ***write*** admin 
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Lay Leangsros
  • 9,156
  • 7
  • 34
  • 39
  • 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 Dec 11 '21 at 20:19
0

In Android Studio Canary build 3.1+, if you are using the Android Studio Git tool, then you can use following:

  • Click on Android Studio
  • Click on Preferences...
  • Go in Version ControlGitHub
  • Here change Auth type to Password
  • This step will require you to enter login and password. Enter your GitHub user name as the login and GitHub password as the password.
  • Click on the Test button.

If the connection is successful, then you are done and you can use the Android Studio GitHub GUI client.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tarun Deep Attri
  • 8,174
  • 8
  • 41
  • 56
0

In case this is tangentially helpful, since this question is now a top hit for http authentication problems with git: Windows Credential Manager had stored my password correctly, and since I was using Git LFS I configured an http URL instead of the usual ssh://.

My problem was that my corporate password policy forced an account password change but I never updated my stored credentials (since I always use an ssh key).

Simply updating the password directly in the Wincred GUI worked: just look for a git:https://<your-url> entry.

msanford
  • 11,803
  • 11
  • 66
  • 93
0

This happened to us after forcing "Two Factor Authentication" before login from Gitlab. We had to paste the text inside id_rsa.pub to Gitlab, and then reintroduce the repository in VS code using the terminal.

Onat Korucu
  • 992
  • 11
  • 13
0

This the way, I resolved my access denied problem in GIT GUI and git bash. SSH KEy

This SSH key is copy-pasted in the GitHub access token.Access Token

For me everything was fine, I also tried the Windows Credentials Manager but then also the problem was not resolved. Then suddenly, I got pop up from the firewall, which was the main culprit behind all. After I clicked on allow manually then I could fetch or push to GitHub.

0

I had just enabled two factor authentication for my Github account, so I disabled two factor authentication and I was able to login with my UID and PWD

Andrew Koper
  • 6,481
  • 6
  • 42
  • 50
0

Given Solution: Using a Personal Access Token is one way of bypassing this problem. I don't have two-factor authentication enabled but whenever, I would login to a new PC I get email verification code to verify PC.

Solution: You can login to GitHub on a browser and verify your identity, that will let GitHub know to trust that PC. Afterwards, login with bash and this time your login should work as usual because now you are whitelisted.


Note: If you have any existing GitHub account and want to switch, then, delete it in Credentials Manager > Windows Credentials (Generic Credentials Section). Doing so will allow you to login when you make another git operation.

Mirwise Khan
  • 1,317
  • 17
  • 25
0

Enabling credentials helper solved the problem for me.

yılmaz
  • 365
  • 1
  • 14
0

I had the same problem. After restarting my System it worked.

Black
  • 18,150
  • 39
  • 158
  • 271
0

THIS IS MY SOLUTION i think it works for Azure, Github or Git. If your authentication is failing could be due to 4 probable reasons -- you enabled 2FA, you changed your password, you changed your username or the repo password is dynamic) --

Whatever it happened you should just FOLLOW FOUR STEPS:

  1. Go wherever you repo is located and click on "CLONE" button.
  2. There should be a HTTPS way and below click on "Generate git credentials" button. This has to give you a new password. (Azure Repos photo)

After clicking in Clone button

  1. Go to your repo in cmd and enter:

    git push -u origin your-Branch-Name

  2. (IF NEEDED) If origin url route is not defined just enter the command below and do step 3 again:

    git remote add origin https://my-git-url

  3. After git push command it will ask your credentials. Use the credentials that you have already generated in your repo.

-1

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Peter
  • 4,493
  • 6
  • 41
  • 64
-1

My solutions is:

  1. Access to C:\Users\USERNAME\AppData\Local\Atlassian\SourceTree
  2. Find the file passwd
  3. Right click on that file and open with Notepad
  4. You will see a list of username and password like:

username@dev.azure.com AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAMUOX3Q56PEuXEBSDFAFAASEH...

  1. Find the username and password you entered incorrectly, and delete it
  2. Save the file, and close it
  3. SourceTree will ask you again for your username and password on the next push or fetch
Quang Dong
  • 467
  • 5
  • 7
-1

For Windows, if username and password does not work for you with https please go through this doc authenticate with https

probably you have to generate a personal access token and use it instead of the password

In newer version of Git recommends using personal access token instead of a password but older versions do not show anything so I was stuck at this point.

Moshiur
  • 659
  • 6
  • 22