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

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

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

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


当前回答

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

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

其他回答

当我只使用git pull,git pull-origin xxx时,git会同时要求用户名和密码。

git config credential.helper store

它起作用。

在GitHub上添加新的SSH密钥,如本文所述。

如果Git仍然要求您输入用户名和密码,请尝试更改https://github.com/到git@github.com:在远程URL中:

$ git config remote.origin.url 
https://github.com/dir/repo.git

$ git config remote.origin.url "git@github.com:dir/repo.git"

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

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

对我来说,当我为我的帐户启用2因素身份验证(2FA)时,出现了此问题。我会输入正确的凭据,但身份验证仍然会失败,因为终端身份验证当然不会要求验证代码。

我只需要为我的帐户禁用2FA。这样做后,我只能在git推送期间输入一次凭据。从那时起,他们就不需要了。

git-config credential.helper存储git推/推https://github.com/xxx.git然后输入您的用户名和密码。多恩