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

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

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

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


当前回答

我使用将我的Git存储库用户名和密码存储在磁盘上。所以每次我推送代码时,git都不会询问用户名和密码

按照以下命令在本地存储中保存凭据

$ git config credential.helper store
or
$ git config --global credential.helper store

从现在起,Git将在第一次访问每个URL上下文时将凭据写入~/.Git凭据文件。要查看此文件的内容,可以使用cat命令,如图所示。

$ cat  ~/.git-credentials

其他回答

更改克隆的存储库可以:

git remote set-url origin git@github.com:gitusername/projectname.git

使用缓存的凭据是有效的,设置超时时间可以减少麻烦。如果您使用Windows凭据助手,这应该是最简单的方法(特别是在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

在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存储库永久验证

运行以下命令以启用凭据缓存:

$ 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

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

如何为Github生成SSH