Bower install using only https?
Asked Answered
L

3

259

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.

Legendary answered 27/3, 2013 at 20:46 Comment(1)
possible duplicate of git: convert "git" urls to "http" urlsHaydeehayden
B
632

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.

Bowshot answered 28/3, 2013 at 14:48 Comment(16)
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.Atonality
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://".insteadOfSafelight
You can also omit --global and it will add the configuration to the local .git/config.Ruderal
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://Chromate
thanx a lot. super usefull command in case of closed ssh (22) portVacate
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.Ordzhonikidze
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.Cowskin
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.Abbey
AnthonyY, how do I define %HOME% ?Greenish
@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://Poisson
If you need it for BOWER, you should use it without the global param.Build
@VincentGauthier In Windows, launch System Properties -> Advanced -> Environment Variables -> SystemVariables -> New -> Add a variable named HOME and set its value to your desired pathBroder
while this does work, it doesnt solve the problem... i want bower to use http, not git to rewrite my urls to http...Gomez
I thought the "shorthand-resolver" setting in .bowerrc would have the same effect, but it does not. Anyone know why?Napalm
this allow us to bypass the entreprise proxy blocking all non http requestForeignism
Thanks, this answer allowed me to download bower packages through Visual Studio 2015 behind a firewall.Ribosome
K
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 https://mcmap.net/q/109246/-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
}
Kop answered 10/12, 2015 at 22:52 Comment(0)
S
0

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

Sula answered 5/8, 2018 at 4:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.