每当我尝试推入我的存储库时,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

其他回答

编辑(由@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帮助凭据

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

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

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

git-config credential.helper存储git推/推https://github.com/xxx.git然后输入您的用户名和密码。多恩

快速方法

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

git config remote.origin.url

那么:

git config credential.helper store

git push "url of your git"

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

完成。