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

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

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

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


当前回答

除了user701648的答案之外,您还可以使用以下命令将凭据存储在主文件夹(所有项目的全局文件夹)中,而不是项目文件夹中

$ git config --global credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>

其他回答

你可以跑了

git config --global credential.helper wincred

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

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

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

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

要查看更改,请使用:

git config --global --edit

如果你使用SSH版本,你将不会有任何密码问题。只有一次你生成SSH密钥,告诉git,这台电脑将使用这个github帐户,并且永远不会再询问我(这台电脑的)任何访问权限。

如何为Github生成SSH

在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"

确保您使用的是SSH而不是http。检查此SO答案。