256

I am trying to set up Bower on a build server at our organization's data center, but git's port does not appear to be open on the data center's firewall. I can use the git command line client to clone via https://[repo], but not git://[repo].

Is there a switch or preference which will instruct bower to perform git clone using https rather than the git protocol?

I've looked at the source, and considered changing the resolution code to replace git:// with https://, but I figured I'd ask before I go to those lengths.

Matt Mills
  • 8,209
  • 6
  • 32
  • 59
  • 2
    possible duplicate of [git: convert "git" urls to "http" urls](http://stackoverflow.com/questions/1722807/git-convert-git-urls-to-http-urls) – Rémi Becheras Nov 19 '14 at 10:35

3 Answers3

627

You can make git replace the protocol for you. Just run:

git config --global url."https://".insteadOf git://

to use HTTPS protocol instead of Git.

kenorb
  • 118,428
  • 63
  • 588
  • 624
Sindre Sorhus
  • 62,754
  • 35
  • 155
  • 217
  • 13
    I feel really dumb. I kept trying the portion of the command prior to .insteadOf thinking that @Sindre was telling us to use git **insteadOf** git. Good grief these english-like commands. – shriek Nov 30 '13 at 03:18
  • 100
    In case anyone else applies this answer and then wonders later how to back out that global configuration change (like me), it's: `git config --global --unset url."https://".insteadOf` – ryan_effectiveui Feb 25 '14 at 21:08
  • 21
    You can also omit `--global` and it will add the configuration to the local `.git/config`. – agentofuser May 27 '14 at 18:45
  • That was good hint, but I was getting `Connection reset by peer` error. But replacing `https` with `http` solved this problem. For me this command worked well: `git config --global url."http://".insteadOf git://` – edufinn Jun 17 '14 at 09:03
  • thanx a lot. super usefull command in case of closed ssh (22) port – iuriisusuk Jun 18 '14 at 15:11
  • This worked but in my case, the git config file was not in USER_HOME, had to use -f switch to specify the path of the config file. – patb23 Nov 12 '14 at 19:57
  • didnt work for me. I am getting this error:bower not-cached git://github.com/jquery/jquery.git#* bower resolve git://github.com/jquery/jquery.git#* bower ECMDERR Failed to execute "git ls-remote --tags --heads git://github.com/jquery/jquery.git", exit code of #128 Additional error details: fatal: '.insteadofgithub.com/jquery/jquery.git' does not appear to be a git repository fatal: Could not read from remote repository. – Ankit Tanna Dec 11 '14 at 07:21
  • 24
    On Windows machine, the global configuration file is .gitconfig under user's home folder, e.g. C:\Users\[username]. However if %HOME% is not defined, git will using %HOMEDRIVE% while git from bower will use %USERPROFILE% instead. Whereas these two variables might be different. On my machine, one is U:, the other is C:\Users\myusername. So the bower still used git:// whatever I tried. It took me a while to figure this out. So write it down in case anybody falls into the same situation. – AnthonyY Dec 16 '14 at 21:59
  • AnthonyY, how do I define %HOME% ? – Samuel Segal Feb 24 '15 at 22:52
  • @VincentGauthier I found it easiest to manually add the content to the .gitconfig in the home directory. You can pick it up from the other location or it will look like `[url "https://"] insteadOf = git://` – Steve Cadwallader Mar 17 '15 at 15:18
  • 1
    If you need it for BOWER, you should use it without the global param. – maxime1992 Mar 26 '15 at 09:17
  • 2
    @VincentGauthier In Windows, launch System Properties -> Advanced -> Environment Variables -> SystemVariables -> New -> Add a variable named HOME and set its value to your desired path – Nick Apr 13 '15 at 18:47
  • while this does work, it doesnt solve the problem... i want bower to use http, not git to rewrite my urls to http... – NDM May 07 '15 at 16:49
  • I thought the ["shorthand-resolver" setting in .bowerrc](https://github.com/bower/spec/blob/master/config.md#shorthand-resolver) would have the same effect, but it does not. Anyone know why? – Ian Phillips Oct 02 '15 at 18:25
  • this allow us to bypass the entreprise proxy blocking all non http request – Nicolas Janel Jan 27 '16 at 10:12
  • Thanks, this answer allowed me to download bower packages through Visual Studio 2015 behind a firewall. – Chris Pickford Feb 23 '16 at 09:59
2

Building on the answer from @Sindre, I wrote a little helper function in BASH which lives in my ~/.bashrc file. Call it just as you would grunt, except now it's called nngrunt. Enjoy!

function nngrunt
{
    # Add a section to the global gitconfig file ~/.gitconfig that tells git to
    # go over http instead of the git protocol, otherwise bower has fits...
    # See http://stackoverflow.com/questions/15669091/bower-install-using-only-https
    git config --global url."https://".insteadOf git://

    # Run grunt w/ any supplied args
    grunt "$@"

    # Now cleanup the section we added to the git config file
    # Of course we have our own extra cleanup to do via sed since the unset command
    # leaves the section around
    # See http://git.661346.n2.nabble.com/git-config-unset-does-not-remove-section-td7569639.html
    git config --global --unset url."https://".insteadOf
    sed -i 's/\[url "https:\/\/"\]//' ~/.gitconfig
    sed -i '/^$/d' ~/.gitconfig
}
quickshiftin
  • 55,146
  • 9
  • 56
  • 76
0

Worked for me git config --global url."git://".insteadOf https://