我从沙盒环境运行git
。这意味着 git 无法看到 ssh-agent ,或者它们通过系统钥匙串(keychain)来获取凭据。现在,我想使用凭证 api2 编写一个自定义凭证助手1,我可以将其与我的可执行文件捆绑在一起并使用它自己的凭证钥匙串(keychain)。
看来,凭证助手只能使用 .gitconfig
为每个 URL 静态配置。
有没有办法通过在命令行上传递自定义帮助器来告诉 git push/pull/fetch
使用自定义帮助程序,或者通过其他方式提供自定义凭据?
1 https://git-scm.com/docs/gitcredentials
2 https://git-scm.com/docs/api-credentials
最佳答案
您可以在调用 git
时使用 -c
选项传递自定义配置参数:
git -c credential.helper=foo push origin master
更重要的是,您可能不需要帮助程序,因为您还可以配置凭据帮助程序以从环境中读取(在本例中为变量 USERNAME
和 PASSWORD
):
git \
-c credential.helper="!f(){ printf 'username=%s\npassword=%s\n' "$USERNAME" "$PASSWORD" };f" \
push origin master
当然,您可能会发现自定义凭据帮助程序比调用 shell 更整洁或更高效,这很好。
关于git - 自定义 Git 凭证助手,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59645494/