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

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

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

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


当前回答

打开Windows凭据管理器并删除git:https://dev.azure.com/orgname来自通用凭据。有关步骤,请查看为什么带有GIT的TFS无法从命令行工作?从文件夹C:\Users\{username}中删除.git凭据文件。确保从更新git最新版本https://git-scm.com/download/win

其他回答

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

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

我尝试了这些步骤,结果成功了:

创建个性化访问令牌:https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token将令牌添加到Android studio(文件->设置->版本控制->Github->添加-使用令牌登录)转到文件->设置->版本控制->Git并取消选中“使用凭据助手”

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

$ git config --global credential.helper cache

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

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

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

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

截至8月13日,2021不再接受基于密码的登录。现在需要使用基于令牌/SSH的身份验证。

如果你不想每次推送时都被问到,请安装GitHubCLI,然后缓存凭据:

git config --global credential.helper store
gh auth login   

并按照提示进行操作。但请确保使用GitHub凭据检查Authenticate Git?带有Y。

使用Git存储库永久验证

运行以下命令以启用凭据缓存:

$ git config credential.helper store
$ git push https://github.com/repo.git

Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>

使用还应指定缓存过期

git config --global credential.helper "cache --timeout 7200"

启用凭据缓存后,将缓存7200秒(2小时)。


读取凭证文档

$ git help credentials