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

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

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

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


当前回答

为了避免输入用户名,但仍会提示您输入密码,您可以简单地克隆存储库,包括用户名:

git clone user_name@example.gitrepo.com/my_repo.git

其他回答

我今天面临这个问题。如果您在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团队

使用以下命令可以给您15分钟的超时时间。

$ git config --global credential.helper cache

您也可以通过下面的命令修改时间。这是一个1小时的示例。

$ git config --global credential.helper 'cache --timeout=3600'

如果要在本地缓存,请使用该命令一小时以超时。

$ git config credential.helper 'cache --timeout=3600'

为了避免输入用户名,但仍会提示您输入密码,您可以简单地克隆存储库,包括用户名:

git clone user_name@example.gitrepo.com/my_repo.git

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

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

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

要查看更改,请使用:

git config --global --edit

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

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