GitHub身份validation通过https失败,返回错误的电子邮件地址

使用GitHub从命令行(通过https,而不是ssh)启动推送或任何其他的操作,不仅要求用户名和密码失败,而且还要返回

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

我没有@github.com地址。 密码和用户名是正确的。

我知道我可以切换到SSH和使用密钥,但不能回答为什么身份validation失败的HTTPS。

GitHub的支持立即确定了问题的根源:双因素授权。

要使用https通过shell使用GitHub,请创build一个OAuth令牌 。 正如页面注释,我不得不从钥匙串中删除我的用户名和密码凭证,但是使用了osx-keychain ,令牌被存储为密码,事情的工作原理与https一样,没有双重授权。

我没有@github.com地址

您不必: @是用户名:密码和域之间的分隔符。
这不是电子邮件地址。

一个完整的GitHub的httpsurl是:

 https://username:password@github.com/username/reponame.git 

如果没有密码(这将在命令行中被询问),那会给:

 https://username@github.com/username/reponame.git 

但是, username@github.com不是电子邮件地址,只是凭证的第一部分。

确保您的usernamereponame正确: 区分大小写 。

请注意,如果您不想在URL中清除所述凭据,则可以在.netrc.gpg (或Windows上的_netrc.gpg )中存储和encryption凭证。
请参阅“ 使用https://github时是否有跳过密码input的方​​法 ”。

[仅限Mac]

如果您需要删除您的身份validation,请使用

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

在Mac上。

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

如果之前存储了不同的凭据,则可能发生在Windows中。 转到凭证pipe理器并删除存储的github凭证

只要incase这也帮助其他人,我login到mac应用程序,命令行工作正常,但因为我然后打开2FA,我的命令返回错误。 我不得不退出应用程序,然后我可以在我的命令中使用我的个人访问令牌。

希望能帮助别人!

在Windows上,您可能会被防病毒或Windows防火墙阻止。 暂时closures这些服务,并从远程来源推/拉。