【问题标题】:Git always ask for my credentials although my credentials are inside .gitconfig尽管我的凭据在 .gitconfig 中,但 Git 总是询问我的凭据
【发布时间】:2021-03-30 10:48:03
【问题描述】:

我使用以下命令将我的凭据存储在 ~/.gitconfig 中:

git config --global user.name "MauroTheCreator"
git config --global user.email "myemail@gmail.com"

但是当我将数据提交到分支并推送数据时,它会再次获取我的凭据

我提交使用

git add stuff
git commit
git push

这真的很烦人,我该如何解决?

【问题讨论】:

  • 这能回答你的问题吗? How to save username and password in Git?
  • 您在.gitconfig 中设置的是要添加到您创建的git commits 的元数据。这与用于向远程(例如 BitBucket、GitHub、GitLab)请求 git push 的凭据不同

标签: git github gitlab


【解决方案1】:

Git 在后台使用credential helpers 来存储您的凭据。 您可以通过运行git config --list 并查找credential.helper 或仅运行git config credential.helper 来检查您的系统上配置了哪个凭据助手。

在 Windows 上,旧版本的 git(Git 2.29 之前)使用 Git Credential Manager For Windows 并将默认助手设置为 credential.helper=manager,而较新的 Git 版本(Git 2.29 或更高版本)使用 Git Credential Manager Core 并将默认助手配置为credential.helper=manager-core.

我没有任何使用 OSX 的经验,但就在线消息来源而言,git config credential.helper 返回credential.helper=osxkeychain

您可以通过运行git credential approve 命令后跟协议、主机、用户名和密码的键值对来告诉 git 存储凭据:

git credential approve
protocol=https
host=github.com
username=<user-name>
password=<pwd/token>
Hit RETURN/ENTER key Twice

您的凭据现在应该已保存。

您可以通过运行git fill 命令来确认:

git credential fill
protocol=https
host=github.com
Hit RETURN/ENTER Key twice

运行上述应返回凭据。 我有一个windows系统。但是由于 git 的命令在任何操作系统上几乎都可以正常工作,因此在 Mac 上也应该可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-01
    • 2017-02-08
    • 1970-01-01
    • 2012-11-29
    相关资源
    最近更新 更多