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

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

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

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


当前回答

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

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

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

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

其他回答

你可以跑了

git config --global credential.helper wincred

在您的系统中安装并登录GIT for windows之后。

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

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

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

git config credential.helper store

它起作用。

git config --global credential.helper cache

编辑(由@dk14根据主持人和评论的建议)

警告:如果您从答案中使用credential.helper存储,您的密码将完全未加密(“原样”)存储在~/.git凭据中。请参阅下面的评论部分或“链接”部分的答案,特别是如果您的雇主对安全问题零容忍的话。

即使被接受,它也不能回答实际OP关于只省略用户名(而不是密码)的问题。对于有这个确切问题的读者,@grawity的答案可能会派上用场。


原始答案(作者@Alexander Zhu):

可以使用以下命令存储凭据

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

此外,我建议您阅读$git帮助凭据