0

I am running the following git clone command:

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

But I get this error:

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

As you can see, git is trying to clone the HTTPS url, which does not exist. Is there any configuration to disable this behavior?

p.s. I trying the following command:

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

And here is the content of ~/.gitconfig file:

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

But I am still getting the same error when running git clone.

P.S.2: I am running this command in a docker container based on the jessie debian image. Could this be the source of the problem?

B Faley
  • 17,120
  • 43
  • 133
  • 223
  • Just tried this and got ```fatal: unable to access 'http://gitlab.example.com/project/component.git/': Could not resolve host: gitlab.example.com``` So maybe it's a matter of an error message and the host i really unreachable? – Kamil Sarna Oct 19 '16 at 13:41
  • @KamilSarna It's a fictitious git URL dude, just to demonstrate the problem. – B Faley Oct 19 '16 at 13:43
  • @Meysam so is the host reachable, and hasn't configured a redirect for that url? – eis Oct 19 '16 at 14:03
  • @eis Yes I can ping it, and can clone the same url on other computers. – B Faley Oct 19 '16 at 14:11
  • 1
    `docker exec -it ping ` What is the output? and `docker exec -it curl ` . Try also with a github repository to see if it is a problem in your container or server. – Carlos Rafael Ramirez Oct 19 '16 at 17:19
  • @CarlosRafaelRamirez I will check this as soon as I get access to the container and will get back to you. – B Faley Oct 19 '16 at 19:39
  • @CarlosRafaelRamirez The ping command works. The curl fetches an html body with this content: `301 Moved Permanently`. I can clone github repositories because they are based on `https`. – B Faley Oct 23 '16 at 08:52
  • If you use `curl -v`, is the location field of the 301 response the https URL that is being reported in your `git clone` error message? Alternatively, use `curl -L` to follow the redirection. – CB Bailey Oct 23 '16 at 09:05
  • @CharlesBailey Yes the location field is the `https` URL reported in `git clone` error message. – B Faley Oct 23 '16 at 09:15
  • So the server is redirecting you to the https url and then reporting that there is nothing at that location. Why do you think the issue is with the use of https and not with the rest of the url? – CB Bailey Oct 23 '16 at 09:22
  • @CharlesBailey Because I am able to clone the given `http` git url on my computer without getting any errors and the same url cannot be cloned on the docker image I have run. So I am guessing it should be the problem with `https` which does not exist. Are you suggesting that `git clone` is always redirected to `https`? If so, why am I able to clone the repository on my computer assuming that the `https` url does not exist on `gitlab`? – B Faley Oct 23 '16 at 09:29
  • @CharlesBailey The point is that I am not redirected to `https` on my computer. The location field after running `curl -v` on my computer is `http`. But this field is `https` on the running docker image. – B Faley Oct 23 '16 at 09:37
  • "The location field after running curl -v on my computer is `http`". So on your computer, what's the difference between the URL you pass to curl and the location field in the redirect. (There must be a difference otherwise there'd be a redirect loop.) – CB Bailey Oct 23 '16 at 09:48
  • @CharlesBailey On my computer: curl input: `http://gitlab.example.com/project/component.git`, location field: `http://gitlab.example.com/project/component` (".git" was removed). On the docker container: curl input: `http://gitlab.example.com/project/component.git`, location field: `https://gitlab.example.com:8070/project/component.git` (http changed to https and port 8070 added) – B Faley Oct 23 '16 at 09:55
  • So either the server you are connecting to treats different clients in different ways based on their ip address or other identification or you have some "transparent" proxies somewhere doing something very strange. Either way, it's not really possible to debug this from the information in the question. – CB Bailey Oct 23 '16 at 10:06
  • @CharlesBailey The problem was fixed. Please take a look at the answer I posted. – B Faley Oct 23 '16 at 11:46

2 Answers2

0

Try to override default protocol for the URL:

$ git config --global url.http://gitlab.example.com/.insteadOf https://gitlab.example.com/
Oleksandr Kravchuk
  • 5,963
  • 1
  • 20
  • 31
0

The problem was the DNS set in /etc/resolv.conf in docker container:

# 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

So I added the IP of the local gitlab to the following file:

/etc/hosts

192.168.20.112 gitlab.example.com

And the problem was fixed.

B Faley
  • 17,120
  • 43
  • 133
  • 223