我用 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/