167

I'm working behind an http proxy. I'm trying to clone Android's source tree using their "repo" tool.

This tool insists on using git:// URLs, even though http:// URLs also work. As a result, I can't download the source.

Is it possible to force git to always use http?

Edit: my http_proxy is configured correctly. For example, this works:

git clone http://android.git.kernel.org/platform/manifest.git

But this doesn't (errno=Connection timed out):

git clone git://android.git.kernel.org/platform/manifest.git

So this answer does not really help me.

jww
  • 97,681
  • 90
  • 411
  • 885
noamtm
  • 12,435
  • 15
  • 71
  • 107

5 Answers5

347

Here's an example of rewriting the default protocol for GitHub:

git config --global url.https://github.com/.insteadOf git://github.com/

The exact values depend on the protocol in use. For example, the above command for git over ssh will look like:

git config --global url.https://github.com/.insteadOf git@github.com:

Git documentation for url.<base>.insteadOf:

git config [--global] url.<base>.insteadOf <other_url>

Any URL that starts with this value will be rewritten to start, instead, with <base>. When more than one insteadOf strings match a given URL, the longest match is used.

Praveen Lobo
  • 6,956
  • 2
  • 28
  • 40
Tobu
  • 24,771
  • 4
  • 91
  • 98
  • 23
    helps when firewall blocks git protocol! :) – Wojtek Turowicz Jun 14 '13 at 15:36
  • Can I ask a question here? I was using this but wrote "heeps" rather than "https". How can I correct this? Does 'git config --global.url.https://github.com/.insteadOf heeps://github.com/' work? – Xuxu Oct 17 '16 at 18:58
  • 3
    Tip: `git remote -v` immediately shows effect of `insteadOf` and `pushInsteadOf` configs – Beni Cherniavsky-Paskin Nov 22 '16 at 13:49
  • This worked for me in public WiFi with blocked 22 port. How config can be reverted to defaults? – yivo Nov 28 '16 at 17:44
  • 15
    This answer almost made it for me, except my repository was using a `git@github.com:...` format for the urls. This worked: `git config --global url."https://github.com/".insteadOf 'git@github.com:'` for me. – kraenhansen Apr 25 '17 at 12:31
  • Thanks! this works on this error ECMDERR Failed to execute "git ls-remote --tags --heads https://github.com/twbs/bootstrap.git", exit code of #128 fatal: unable to access 'https://github.com/twbs/bootstrap.git/': SSL certificate problem: self signed certificate in certificate chain – Rh Jov Oct 30 '17 at 06:20
  • I'm getting error: cannot overwrite multiple values with a single value – Jake Sylvestre Oct 18 '18 at 06:28
  • Thanks! Exact solution, worked for me I was getting this error: "C:\Program Files\Git\cmd\git.EXE ls-remote -h -t git://github.com/shahata/jsdelivr-cdn-data.git – MANJEET Oct 11 '19 at 12:15
35

I don't know how this repo tool uses Git (and if you can configure 'repo' to use http protocol), but you can try to trick it using url.<base>.insteadOf configuration variable (see git-config and git-fetch manpages).

Have you tried to use core.gitProxy to pass through firewall, if it is the problme with using git protocol?

Jakub Narębski
  • 309,089
  • 65
  • 217
  • 230
27

I had this same problem with recursively getting submodules in a git repository. I'm behind a crazy firewall that doesn't allow outgoing connections on the git port. Some of the submodules of the submodules were coded as git://github.com/blah/blah.git. This killed my recursive population of submodules. The workaround is the following:

git config --global url."https://<GITUSERNAME>@".insteadOf git://

This replaces git:// with https://<GITUSERNAME>@ in all submodule repository URLs. You need to replace <GITUSERNAME> with your own git username. Also note that the --global is required; just adding this configuration to the base repository directory doesn't work.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
crcastle
  • 630
  • 5
  • 8
  • 3
    Y not just use git config --global url."https://".insteadOf git:// as shown here? https://github.com/angular/angular-phonecat/issues/141 I mean is the username mandatory? – agelbess Jun 19 '15 at 07:11
4

You can verify in ~/.gitconfig if you're overwriting SSH with https://, or vice versa.

Piper
  • 1,266
  • 3
  • 15
  • 26
0

Find your git account's git config file(.gitconfig), modify the followings:

    [user]
    email = your e-mail account


    name = your git account
    [url "git@github.com:"]


    insteadOf = https://github.com/