首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >脚本git克隆使用git凭据管理器失败。

脚本git克隆使用git凭据管理器失败。
EN

Stack Overflow用户
提问于 2022-09-23 17:56:05
回答 1查看 48关注 0票数 0

我有一个开发人员工作站配置脚本,在那里我试图克隆出基本代码开发人员的工作。

但是,当向git凭据管理器提供凭据时,脚本会抛出一个错误。

剧本:

代码语言:javascript
运行
复制
# configure git credential manager
git credential-manager-core configure

# add service account credentials to the credential manager; this is where it throws the error
printf "host=private.bitbucket.instance.example.com\nprotocol=https\nusername=GitServiceAccount@example.com\npassword=ComplexPassword" | git credential-manager-core store

# clone out code
git clone https://private.bitbucket.instance.example.com/path/developercode.git

# remove service account credentials from the credential manager
printf "host=private.bitbucket.instance.example.com\nprotocol=https\nusername=GitServiceAccount@example.com" | git credential-manager-core erase

错误:

代码语言:javascript
运行
复制
fatal: Unable to persist credentials with the 'wincredman' credential store.
See https://aka.ms/gcm/credstores for more information.

信息页声明“由于Windows中的限制,GCM无法将凭据持久化到Windows凭据管理器”。

如何将git凭据存储在供应脚本中,如上面所示?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-23 21:17:20

我不使用Windows,但我认为凭据管理器的Windows后端需要一个带有图形会话的登录用户,这可能就是这种方法无法工作的原因。

相反,您可以简单地提供来自环境如Git FAQ中所述的凭据。然后,只需在适当的环境变量中设置密码或令牌,操作就会自动使用正确的凭据。如果同时执行其他Git操作,这些操作将在环境中没有密码或令牌,并且无法从凭据助手处读取数据,则这样做也更安全。

设置凭据助手的命令如下(假设您的令牌在$GIT_TOKEN中):

代码语言:javascript
运行
复制
$ git config --global credential.helper \
    '!f() { echo username=author; echo "password=$GIT_TOKEN"; };f'
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73831375

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档