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

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

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

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


当前回答

快速方法

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

git config remote.origin.url

那么:

git config credential.helper store

git push "url of your 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/

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

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

git config credential.helper store

它起作用。

当一个人使用HTTPS而不是SSH下载时,就会出现这种情况。我实现的最简单的方式是,当我做了一些更改时,我推送了所有内容,其中要求输入用户名和密码,然后我从我的机器中删除了目录,并将其从gitclone SSH地址中删除。解决了。

只需使用SSH而不是HTTP克隆它,它就不会要求用户名或密码。

另外,即使使用SSH下载,使用双因素身份验证也会产生问题,因此禁用它可以解决问题。

设置全天(即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