每次我尝试向我的repo推送时,git都要求输入用户名和密码
。
我每次重新输入密码都没有问题,但问题是输入用户名。我使用https
来克隆我的存储库。
那么,如何配置git,使其不会在每次git push
时要求输入用户名
。
我是Linux新手,但如果我没记错,在Windows中git push
只需要输入密码。
每次我尝试向我的repo推送时,git都要求输入用户名和密码
。
我每次重新输入密码都没有问题,但问题是输入用户名。我使用https
来克隆我的存储库。
那么,如何配置git,使其不会在每次git push
时要求输入用户名
。
我是Linux新手,但如果我没记错,在Windows中git push
只需要输入密码。
编辑(通过@dk14的建议进行修改,由管理员和评论)
警告:如果您使用答案中的credential.helper store
,则您的密码将完全未加密(“原样”)存储在~/.git-credentials
中。如果您的雇主对安全问题毫无容忍,请参阅下面的评论部分或“关联”部分的答案。
尽管已经被接受,但它并没有回答实际的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 help credentials
git config --unset credential.helper
以取消凭据助手。 - dk14.git/config
文件中完成这个操作。该文件包含一个名为“remote”的部分,其中有一个名为“url”的条目。 “url” 条目应包含您要讨论的存储库的 https 链接。git
就不再需要询问您的用户名了。以下是一个示例:url = https://username@repository-url.com
git config credential.helper store
安全风险。 - RayLuossh: Could not resolve hostname https: No address associated with hostname
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
你确定你的示例是正确的吗? - Zoey Hewll无法访问'https://<me>@bitbucket.org:<x>/<y>.git/': 非法的端口号
。 - Ian Grainger按照GitHub上这篇文章的说明添加新的SSH密钥。
如果Git仍然要求输入用户名和密码,请尝试在远程URL中将https://github.com/
更改为git@github.com:
。
$ git config remote.origin.url
https://github.com/dir/repo.git
$ git config remote.origin.url "git@github.com:dir/repo.git"
git config remote.origin.url "ssh://git@yourRepoHost/yourRepoName.git"
。 - ndarknessgit@github
的 URL 是可行的,但我还需要创建一个个人访问令牌和 SSH 密钥才能使我的身份验证工作正常。 - Dani Amsalem运行以下命令启用凭据缓存:
$ git config credential.helper store
$ git push https://github.com/repo.git
Username for 'https://github.com': <USERNAME>
Password for 'https://USERNAME@github.com': <PASSWORD>
使用时应指定缓存过期时间
git config --global credential.helper "cache --timeout 7200"
启用凭证缓存后,它将被缓存 7200秒(2小时)。
阅读凭证文档
$ git help credentials
我发现最简单的方法是使用这个命令:
git config --global credential.https://github.com.username <your_username>
这适用于按网站进行的设置,并修改您的全局git配置。
要查看更改,请使用:
git config --global --edit
.git/config
中编辑"url"就像user701648所说的那样,但如果您愿意,也可以添加密码:url = https://username:password@repository-url.com
@
,会怎么样呢?
url = https://username:abc@123@repository-url.com
它给我返回了错误信息:Could not resolve host: @123@git.com
。 - Rahul Mankar%40
代替 @
。
例如:url = https://name%40domain.com:password@repository-url.com
- DEnergit config --global credential.helper cache
[credential "https://example.com"]
username = me
(这直接来自于 "git help credentials")
复制的存储库进行更改是有效的:
git remote set-url origin git@github.com:gitusername/projectname.git
使用缓存凭据是有效的,设置超时时间可以使事情变得不那么烦人。如果您使用Windows凭据助手,则应该是最简单的方法(特别是如果SSH被阻止)。
git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.
我不建议使用这种方法。 - sh37211除了user701648的答案之外,您还可以使用以下命令将凭据存储在您的主文件夹中(全局适用于所有项目),而不是项目文件夹中:
$ git config --global credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>