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

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

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

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


当前回答

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

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

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

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

其他回答

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

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

解决这个问题的正确方法是将http更改为ssh。

您可以使用此git remote rm源来删除远程回购。

然后,您可以使用ssh-sintax(可以从github复制)再次添加它:git远程添加原点git@github.com:username/reportname.git。

检查这篇文章。https://www.freecodecamp.org/news/how-to-fix-git-always-asking-for-user-credentials/

快速方法

在工作目录中获取git的url:

git config remote.origin.url

那么:

git config credential.helper store

git push "url of your git"

将最后一次询问用户名和密码

完成。

设置全天(即24小时)的凭据。

git config --global credential.helper 'cache --timeout=86400'

否则1小时,将86400秒替换为3600秒。

OR

“缓存”身份验证助手的所有配置选项:

git帮助凭据缓存

有关详细信息:https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git

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

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