从命令行将范围 PAT 添加到 git 凭证助手

Add scoped PAT to git credential helper from command line

我有一个 Gitlab CI 管道,它正在构建一个 Unity 项目,其中包含从 git 存储库中提取的包。有许多软件包,但它们都属于两个组中的一个,我可以获得两者的 PAT(由于某些其他限制,我无法在此特定实例中使用 SSH 密钥)。 Unity 使用 git 凭据管理器对包进行身份验证 (details),但我不确定如何从命令行将这些凭据实际添加到帮助程序。

运行器在 Windows 10 机器上使用 Shell 执行器,我可以使用环境变量注入 PAT,但我不知道如何获取它们添加到凭据管理器,在这种情况下,它们需要限定在类似于 的特定组 URL 范围内。此计算机上的 git 安装也配置为使用 Windows 凭据管理器。

how to do is get them added to the credential manager

在命令行中

printf "host=remote.host.name\nprotocol=https\nusername=aUser\npasswprd=<yourPAT>" | \
git credential-manager-core store

(作为 by the OP Alex McCraw, that requires installing the latest Git for Windows,2.35.1.2,在撰写本文时,2022 年第一季度)

假设在 Windows 10 台机器上执行时:

  • git config credential.helper returns credential-manager-core
  • git-credential-manager-core.exe 在 PATH 中(或者您需要使用完整路径 C:\Program Files\Git\mingw64\libexec\git-core\git-credential-manager-core.exe