GitHub authentication failing over https, returning wrong email address

GitGithubHttps

Git Problem Overview


Initiating a push or any other action with GitHub from the command line (over https, not ssh) that calls for the username and password not only fails but, when it does, it returns

Username for 'https://github.com': username
Password for 'https://[email protected]': 
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/username/repository.git/'

I do not have an @github.com address. The password and username are correct.

I know I could switch to SSH and use keys but that doesn't answer why the authentication is failing over https.

Git Solutions


Solution 1 - Git

GitHub's support determined the root of the issue right away: Two-factor authorization.

To use GitHub over the shell with https, create an OAuth token. As the page notes, I did have to remove my username and password credentials from Keychain but with osx-keychain in place, the token is stored as the password and things work exactly as they would over https without two-factor authorization in place.

Solution 2 - Git

> I do not have an @github.com address

You don't have to: the @ is the separator between the username:password and the domain.
It is not an email address.

A full GitHub https url would be:

# 2014:
https://username:[email protected]/username/reponame.git

# 2021+:
https://username:[email protected]/username/reponame.git

Without the token (which would then be asked on the command line), that would give:

https://[email protected]/username/reponame.git

But again, [email protected] isn't an email address, just the first part of the credentials.

Make sure the case of your username and reponame is correct: it is case-sensitive.


Since Aug. 2021, GitHub no longer accept account passwords when authenticating Git operations on GitHub.com.
Only PAT (Personal Access Token)


Note that you can store and encrypt your credentials in:

Solution 3 - Git

  • Go to Credential Manager => Windows Manager
  • Delete everything related to tfs
  • Now click on Add a generic credential and provide the following values

(1) Internet or network adress: git:https://tfs.donamain name (2) username: your username (3) password: your password

this should fix it

Solution 4 - Git

It may happen in Windows if you stored a different credentials before. Go to Credential Manager and delete stored github credentials

Solution 5 - Git

[Mac only]

If you need to delete your authentication, use

git credential-osxkeychain erase
host=github.com
protocol=https

on Mac.

See https://help.github.com/articles/updating-credentials-from-the-osx-keychain/

Solution 6 - Git

Same thing happened with me, when i have enabled 2-way authentication for github. Things i did to resolve:

  • Get you personal access token. This you have to check and generate if not available already. Link for this: https://github.com/settings/tokens
  • Go to your local and delete folder and re-clone branch from github.
  • Now try the command you were trying earlier i.e: git pull origin master
  • Enter username and In password paste the token generated and also don't forget to save that token somewhere, so you can re-use if required.

Doing this will solve your issue.

Solution 7 - Git

Just incase this helps anyone else also, I was signed into the mac app, command line working fine, but because I then turned on 2FA, my commands were returning the error. I had to sign out of the app, then I could use my Personal access token in my commands as per ele's answer here.

Hopefully that helps someone!

Solution 8 - Git

  • Go to https://github.com/settings/tokens to generate your tokens
  • Generate your token and store it safely
  • Now try to push your code to github
  • Two times you have to give your credentials. First time provide your gmail and password and second time provide your username and the generated token instead of password(at the password field).
  • another thing is , if you go to your github profile then you will find your username at the url

It works for me , hoping it will save your time . Best wishes .

Solution 9 - Git

On Windows, you may be silently blocked by your Antivirus or Windows firewall. Temporarily turn off those services and push/pull from remote origin.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestioneleView Question on Stackoverflow
Solution 1 - GiteleView Answer on Stackoverflow
Solution 2 - GitVonCView Answer on Stackoverflow
Solution 3 - GitJemil OyebisiView Answer on Stackoverflow
Solution 4 - GitRandomView Answer on Stackoverflow
Solution 5 - GitDan RosenstarkView Answer on Stackoverflow
Solution 6 - GitpalakView Answer on Stackoverflow
Solution 7 - GitJoel BalmerView Answer on Stackoverflow
Solution 8 - GitChayan RoyView Answer on Stackoverflow
Solution 9 - GitVortexView Answer on Stackoverflow