为什么 "git clone" 正在尝试使用 https

Why "git clone" is trying to use https

我是运行以下git clone命令:

git clone http://gitlab.example.com/project/component.git

但是我得到这个错误:

Cloning into 'component'...
fatal: repository 'https://gitlab.example.com/project/component.git/' not found

如您所见,git 正在尝试克隆不存在的 HTTPS url。是否有任何配置可以禁用此行为?

p.s。我尝试以下命令:

$ git config --global url.http://gitlab.example.com/.insteadOf https://gitlab.example.com/

这里是 ~/.gitconfig 文件的内容:

[http]
    sslverify = false
[url "http://gitlab.example.com/"]
    insteadOf = https://gitlab.example.co

但是当 运行 git clone 时我仍然遇到同样的错误。

P.S.2: 我在 运行 这个命令基于 jessie debian image 的 docker 容器中。这可能是问题的根源吗?

尝试覆盖 URL 的默认协议:

$ git config --global url.http://gitlab.example.com/.insteadOf https://gitlab.example.com/

问题是 docker 容器中 /etc/resolv.conf 中的 DNS 设置:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
search example.com

nameserver 8.8.8.8
nameserver 8.8.4.4

于是我将本地gitlab的IP添加到如下文件中:

/etc/hosts

192.168.20.112 gitlab.example.com

问题已解决。