【问题标题】:Using gcloud's credential helper to access Google Source Repositories prevents osxkeychain from working使用 gcloud 的凭证助手访问 Google 源代码库会阻止 osxkeychain 工作
【发布时间】:2025-12-14 10:35:01
【问题描述】:

Google Source Repositories docs 中,它要求您使用git config credential.helper gcloud.sh 来允许Git 进行身份验证

最近,这阻止了我在 GitHub 上使用 osxkeychain auth - 添加该命令后,当我尝试从 GitHub 拉取时收到此错误消息(在唯一远程是 GitHub 远程的 repo 上):

git pull 

remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/[].git/'

请注意,它甚至不会再次询问我的用户名和密码;它立即拒绝连接

如果我从 git config 中删除 gcloud credential.helper,我可以使用 GitHub 重新进行身份验证(尽管需要再次输入我的用户名和密码)

我正在使用git version 2.15.1gcloud

Google Cloud SDK 183.0.0
alpha 2017.09.15
beta 2017.09.15
bq 2.0.27
container-builder-local
core 2017.12.08
datalab 20171003
gcloud
gsutil 4.28
kubectl

【问题讨论】:

    标签: git gcloud google-cloud-source-repos


    【解决方案1】:

    这里的问题是指令覆盖了可能存在的凭证助手。要将凭据帮助程序限制为仅适用于 Google Source Repositories,请运行:

    git config credential.'https://source.developers.google.com'.helper gcloud.sh
    

    或更改您的 .git/config

    [credential]
            helper = gcloud.sh
    

    [credential "https://source.developers.google.com"]
            helper = gcloud.sh
    

    【讨论】:

    • 目前看起来很棒! ...甚至可能是文档中的答案
    【解决方案2】:

    您只需为 Google Cloud 存储库设置凭据帮助程序,而不是系统范围。

    对于 github,也可以考虑使用 ssh-keys 代替用户名/密码:https://help.github.com/articles/connecting-to-github-with-ssh/

    【讨论】:

    • 如何仅针对 Google Cloud 存储库进行设置? git config 的默认值无论如何都是 --local,尽管它是一个来自 GH 和 Google Cloud 的存储库,因此需要存在于 --local
    • SSH 是可能的,虽然它是一个解决问题的方法,并且阻止使用 GitHub 的用户名和密码