git - go get 不适用于引用自定义 gitconfig 的 .gitconfig

标签 git git-config go-get

我用 git clone 克隆了一个存储库它依赖于另一个私有(private)仓库。在当前 repo 中,我尝试 go get该依赖项( go get -u ./... )它给我一个错误:

fatal: could not read Username for 'https://bitbucket.org': terminal prompts disabled


信息
  • 我用了git clone git@my-name.bitbucket.org:company/repo.git将 repo 克隆到 ~/Desktop/BitBucket/Company目录。
  • 我有 GOPRIVATE="bitbucket.org/company/*"
  • 没有 includeIf 一切正常.如果我替换 .gitconfig 公司 .gitconfig 它工作正常。但是我需要管理多个帐户...
  • 命令git config --get user.name (在 repo 内)返回 My Name .所以go get有问题

  • 我的 主 .gitconfig 文件(在 $HOME 目录中):
    [includeIf "gitdir/i:~/Desktop/BitBucket/Company/"]
            path = ~/.git/BitBucket/Company/.gitconfig
    
    我的 .gitconfig 文件(用于公司 repo $HOME/.git/BitBucket/Company/.gitconfig):
    [user]
            name = My Name
            email = my.name@company.com
    [url "git@my-name.bitbucket.org:"]
            insteadOf = https://bitbucket.org/
    
    我的 ssh 配置 文件($HOME/.ssh/config):
    Host my-name.bitbucket.org
      Hostname bitbucket.org
      PreferredAuthentications publickey
      IdentityFile ~/.ssh/keys/BitBucket/my_name/id_rsa
    
    我的错误是什么?
    我还找到了这篇文章:https://medium.com/easyread/today-i-learned-fix-go-get-private-repository-return-error-terminal-prompts-disabled-8c5549d89045 .您可以查看第一条评论:

    FYI, this dont work when using .gitconfig that references a custom .gitconfig-custom. It has to live in ~/.gitconfig….. man that was frustrating.


    我试图移动公司 .gitconfig 到主目录(+ 将其重命名为 .gitconfig-company)。没有任何效果。

    最佳答案

    如果您使用 go get要克隆存储库,请注意 gitdir:gitdir/i:模式与正在克隆的存储库不匹配。这是因为该模式匹配 .git 的目录。目录,当你克隆时,.git目录尚未创建。
    您可以尝试将这样的指令放入您的配置中:

    [url "git@my-name.bitbucket.org:company/"]
            insteadOf = https://bitbucket.org/company/
    
    如果您需要克隆其他(公共(public))存储库,然后为 Bitbucket 设置一个非工作 key 。

    关于git - go get 不适用于引用自定义 gitconfig 的 .gitconfig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65355577/

    相关文章:

    git - 将较新的 Git 存储库附加到较旧的存储库以 merge 两个历史记录

    git - 子目录的最新提交哈希

    git - 远程 ssh session 期间的本地 git 配置

    git - 由于区分大小写,无法将文件添加到 git 中的暂存区

    git - 在 Git 存储库中查找早于特定日期的文件

    git - 如何告诉 git 为给定项目使用正确的身份(名称和电子邮件)?

    Git:我可以禁止在状态、差异等中列出 'modified content'/脏子模块条目吗?

    go - 强制 `go get` 和 `go install` 使用缓存,即使它是古老的

    去获取谷歌的云源代码库

    git - 从私有(private)存储库获取依赖项的正确方法