git credential.helper 不存储用户名密码

iam*_*ads 7 git bash expect azure-devops

我正在编写一个部署脚本,它克隆一个 git repo,然后执行其他任务,例如 fetch 等。我已经运行了这个

git config --global credential.helper cache
Run Code Online (Sandbox Code Playgroud)

克隆步骤的用户名和密码由期望脚本提供。但是这些详细信息并没有按原样缓存。脚本再次提示输入用户详细信息

我无法使用 ssh,因为我使用的是 Visual Studio Online

小智 13

很旧的线程,但我今天发现了它,所以......

在告诉 git 在哪里存储凭证后,它在我的设置(Ubuntu 服务器 20.04 LTS)中工作。Ubuntu 中似乎没有默认设置:

$ git config --global credential.helper 'store --file ~/.my-credentials'
Run Code Online (Sandbox Code Playgroud)

通过将其与:

$ git config --global credential.helper store
Run Code Online (Sandbox Code Playgroud)

一切顺利。

来源:https ://git-scm.com/book/en/v2/Git-Tools-Credential-Storage

  • @NickMancuso 谢谢这对我有用 (2认同)

小智 8

您可以创建这样的文件~/.netrc

machine github.com
login <username>
password <password>
Run Code Online (Sandbox Code Playgroud)

Git 会使用它。另一种选择是git-credential-store

git config --global credential.helper store
Run Code Online (Sandbox Code Playgroud)

凭据保存到~/.git-credentials.