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

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

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

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


当前回答

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

其他回答

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

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

ssh+密钥身份验证比https://credential.helper更可靠

您可以配置为对所有存储库使用SSH而不是HTTPS,如下所示:

git config --global url.ssh://git@github.com/.insteadOf https://github.com/

网址<此处记录了base>.installOf。

为了避免输入用户名,但仍会提示您输入密码,您可以简单地克隆存储库,包括用户名:

git clone user_name@example.gitrepo.com/my_repo.git

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

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

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

要查看更改,请使用:

git config --global --edit

快速方法

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

git config remote.origin.url

那么:

git config credential.helper store

git push "url of your git"

将最后一次询问用户名和密码

完成。