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

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

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

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


当前回答

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

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

其他回答

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

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

如果您使用的是https而不是ssh,您可以按照user701648所说的那样在.git/config中编辑“url”,但如果您愿意,也可以添加密码:

url = https://username:password@repository-url.com

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

最简单的方法是创建包含以下内容的~/.netrc文件:

machine github.com
login YOUR_GITHUB_USERNAME
password YOUR_GITHUB_PASSWORD

(如下所示:https://gist.github.com/ahoward/2885020)

您甚至可以关闭此文件的权限,以便没有人可以通过键入以下内容读取您的密码:

chmod 600 ~/.netrc

快速方法

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

git config remote.origin.url

那么:

git config credential.helper store

git push "url of your git"

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

完成。