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

Kli*_*mbo 6 git git-config go-get

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

致命:无法读取“https://bitbucket.org”的用户名:终端提示已禁用

信息

  • 我曾经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
Run Code Online (Sandbox Code Playgroud)

我的.gitconfig文件(用于公司仓库$HOME/.git/BitBucket/Company/.gitconfig):

[user]
        name = My Name
        email = my.name@company.com
[url "git@my-name.bitbucket.org:"]
        insteadOf = https://bitbucket.org/
Run Code Online (Sandbox Code Playgroud)

我的ssh 配置文件($HOME/.ssh/config):

Host my-name.bitbucket.org
  Hostname bitbucket.org
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/keys/BitBucket/my_name/id_rsa
Run Code Online (Sandbox Code Playgroud)

我的错误是什么?

我还发现了这篇文章:https : //medium.com/easyread/today-i-learned-fix-go-get-private-repository-return-error-terminal-prompts-disabled-8c5549d89045。您可以查看第一条评论:

仅供参考,这在使用引用自定义 .gitconfig-custom 的 .gitconfig 时不起作用。它必须存在于 ~/.gitconfig ..... 令人沮丧的人。

我试图将公司 .gitconfig移动到主目录(+ 将其重命名为 .gitconfig-company)。什么都行不通。

bk2*_*204 4

如果您要用于go get克隆存储库,请注意 和gitdir:模式gitdir/i:与正在克隆的存储库不匹配。这是因为该模式匹配的目录是.git目录,当您克隆时,.git目录尚未创建。

您可以尝试将这样的指令放入您的配置中:

[url "git@my-name.bitbucket.org:company/"]
        insteadOf = https://bitbucket.org/company/
Run Code Online (Sandbox Code Playgroud)

然后,如果您需要克隆其他(公共)存储库,请为 Bitbucket 设置非工作密钥。