每当我尝试推入我的存储库时,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-config credential.helper存储git推/推https://github.com/xxx.git然后输入您的用户名和密码。多恩

您可以通过在Git配置文件中放置以下内容来设置给定站点上所有存储库的用户名。你会想改变的”https://example.com“和”我“添加到实际URL和您的实际用户名。

[credential "https://example.com"]
    username = me

(这直接来自“git help credentials”)

快速方法

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

git config remote.origin.url

那么:

git config credential.helper store

git push "url of your git"

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

完成。

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

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

使用以下命令可以给您15分钟的超时时间。

$ git config --global credential.helper cache

您也可以通过下面的命令修改时间。这是一个1小时的示例。

$ git config --global credential.helper 'cache --timeout=3600'

如果要在本地缓存,请使用该命令一小时以超时。

$ git config credential.helper 'cache --timeout=3600'