首页 > 解决方案 > 去使用 ssh 而不是 https(不在 github 上)

问题描述

我们有一个只能通过 ssh/git(没有 https)访问的私有代码存储库,我们希望在那里托管我们的 go 代码/模块。

首先我试过:

git config --global url."git@code.internal.local:".insteadOf "https://code.internal.local/"

所以,以下两项工作都很好:

但是go get code.internal.local/reponame失败了,因为 go 仍然坚持尝试 https://... 而不是 git。

package code.internal.local/reponame: unrecognized import path "code.internal.local/reponame": https fetch: Get "https://code.internal.local/reponame?go-get=1": dial tcp 192.168.0.5:443: i/o timeout

标签: gitgogo-modules

解决方案


我检查了我的.gitconfig并找到了这个(对于github私人仓库) -

[url "ssh://git@github.com/"]
        insteadOf = https://github.com/

上面的配置对我有用。您也可以尝试在项目根目录中创建一个.netrc文件,但不应其推送到远程代码仓库。


推荐阅读