ChatGPT解决这个技术问题 Extra ChatGPT

Bower install using only https?

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.


k
kenorb

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.


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.
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
You can also omit --global and it will add the configuration to the local .git/config.
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.
@VincentGauthier In Windows, launch System Properties -> Advanced -> Environment Variables -> SystemVariables -> New -> Add a variable named HOME and set its value to your desired path
q
quickshiftin

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
}

M
Mansoor Ul Haq

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