每当我尝试推入我的存储库时,git都会要求用户名和密码。

每次重新输入密码没有问题,但问题是输入用户名。我使用https克隆存储库。

那么,我如何配置git,使它在每次git推送时都不需要用户名。

我是linux新手,但windows git push中的IIRC只要求输入密码。


当前回答

我找到的最简单的方法是使用以下命令:

git config --global credential.https://github.com.username <your_username>

这会逐个站点工作,并修改全局git配置。

要查看更改,请使用:

git config --global --edit

其他回答

我今天面临这个问题。如果您在2020年11月面临此问题,则需要更新git版本。我收到一封电子邮件,告诉我这件事。下面是github团队的电子邮件内容。

我们检测到您最近试图向GitHub进行身份验证使用旧版本的Git for Windows。GitHub改变了用户在使用Git for Windows时进行身份验证,现在需要使用web浏览器验证GitHub。能够登录通过web浏览器,用户需要更新到最新版本的Git窗户。您可以在以下位置下载最新版本:https://gitforwindows.org/如果您无法将Git for Windows更新到最新版本,请参阅有关详细信息和建议的解决方法,请单击以下链接:https://aka.ms/gcmcore-githubauthchanges如果您对这些更改有任何疑问或需要帮助,请联系GitHub支持,我们很乐意进一步协助。https://support.github.com/contact谢谢,GitHub团队

如果您使用的是https而不是ssh,您可以按照user701648所说的那样在.git/config中编辑“url”,但如果您愿意,也可以添加密码:

url = https://username:password@repository-url.com

我找到的最简单的方法是使用以下命令:

git config --global credential.https://github.com.username <your_username>

这会逐个站点工作,并修改全局git配置。

要查看更改,请使用:

git config --global --edit

ssh+密钥身份验证比https://credential.helper更可靠

您可以配置为对所有存储库使用SSH而不是HTTPS,如下所示:

git config --global url.ssh://git@github.com/.insteadOf https://github.com/

网址<此处记录了base>.installOf。

你可以跑了

git config --global credential.helper wincred

在您的系统中安装并登录GIT for windows之后。