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

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

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

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


当前回答

您可以通过在Git配置文件中放置以下内容来设置给定站点上所有存储库的用户名。你会想改变的”https://example.com“和”我“添加到实际URL和您的实际用户名。

[credential "https://example.com"]
    username = me

(这直接来自“git help credentials”)

其他回答

使用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

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

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

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

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

git config credential.helper store

它起作用。

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

如何为Github生成SSH