我试图在我们组织的数据中心的构建服务器上设置Bower,但git的端口在数据中心的防火墙上似乎没有打开。我可以使用git命令行客户端通过https://[repo]克隆,但不是git://[repo]。

是否有一个开关或首选项,将指示bower执行git克隆使用https而不是git协议?

我已经查看了源代码,并考虑更改分辨率代码,将git://替换为https://,,但我想在我去那些长度之前,我应该问一下。


当前回答

基于@Sindre的回答,我在BASH中写了一个小的帮助函数,它位于我的~/中。bashrc文件。(就像你会grunt一样调用它,除了现在它被称为nngrunt。享受吧!

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
}

其他回答

为我工作 Git配置——全局url." Git://"。与其使用https://

基于@Sindre的回答,我在BASH中写了一个小的帮助函数,它位于我的~/中。bashrc文件。(就像你会grunt一样调用它,除了现在它被称为nngrunt。享受吧!

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
}

你可以让git代替你的协议。运行:

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

使用HTTPS协议代替Git。