git - 去获取 : Git settings are ignored

标签 git go go-get

我尝试从 mac 上的私有(private) gitlab 服务器获取存储库。

我将 git 配置 (~/.gitconfig) 设置为使用 ssh 而不是 https:

[url "git@gitlab.mysite.com:"]
    insteadOf = https://gitlab.mysite.com/

当我使用 https url 克隆项目时,我得到了正确的替换

$ git clone https://gitlab.mysite.com/group/project
$ cd project
$ git remote -v
origin  git@gitlab.mysite.com:group/project (fetch)
origin  git@gitlab.mysite.com:group/project (push)

但是,当我使用 go get 时,它尝试使用 https url,但失败了

$ go get gitlab.mysite.com/group/project
package gitlab.mysite.com/group/project: unrecognized import path "gitlab.mysite.com/group/project" (https fetch: Get https://gitlab.mysite.com/group/project?go-get=1: x509: certificate signed by unknown authority)

为什么 go get 不使用我的 git 配置?我该如何解决?

我知道这个问题类似于这个问题:go get: Git settings ignored以及有关私有(private) repo 的许多其他问题

我的问题不同

最佳答案

该错误发生在 git clone 调用之前。当您调用 go get 时,它会向 URL 发出 HTTPS 调用以检查 header 并查看它是否提供 go get 重定向。这就是失败的原因。

它失败了,因为服务器提供的证书不是由您在本地系统上指定为受信任的证书颁发机构签署的。这可能是因为您的内部 gitlab 正在使用未签名的证书,因为用于签署它的 CA 尚未添加到您的本地系统,或者因为您的工作场所正在使用中间人式代理而您没有没有添加该代理的 CA。您可以尝试修复证书问题,也可以简单地运行:

go get -insecure gitlab.mysite.com/group/project

The -insecure flag permits fetching from repositories and resolving custom domains using insecure schemes such as HTTP. Use with caution.

值得注意的是,这会绕过用于签署服务器证书的 CA 的验证。

关于git - 去获取 : Git settings are ignored,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52404171/

相关文章:

Git RPC 失败;结果=22,HTTP 代码=400

git - git ls-remote 和 git ls-remote origin 之间的区别

GoLand IDE 无法正确编译。如何设置正确的路径?

从 codecommit 获取私有(private)仓库

docker - 在 Docker 中,无法 cd 进入安装了 "go get"的目录?

go - 如何在本地运行 pkg.go.dev 作为 godoc 替代品?

git - 从 .git 目录生成工作目录文件

git - 错误 : Repository not found. 致命:无法从远程存储库读取

go - 使用 GoLang Web 服务器提供静态内容

go - 通过 channel 在 Go 中进行通信