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

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

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

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


当前回答

git config --global credential.helper cache

其他回答

git config --global credential.helper cache

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

解决这个问题的正确方法是将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配置文件中放置以下内容来设置给定站点上所有存储库的用户名。你会想改变的”https://example.com“和”我“添加到实际URL和您的实际用户名。

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

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

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

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