只使用https安装Bower?

259

我正在尝试在我们组织的数据中心上的构建服务器上安装Bower,但是据我观察,git端口未在数据中心的防火墙上打开。我可以使用git命令行客户端通过https://[repo]进行克隆,但无法使用git://[repo]

是否有一种开关或首选项可以指示bower使用https而不是git协议执行git clone操作?

我已经查看了源代码,并考虑更改解析代码以将git://替换为https://,但在采取这些措施之前,我想先询问一下。


2
可能是 git:将“git” URL 转换为“http” URL 的重复。 - Rémi Becheras
3个回答

632

你可以让 Git 为你替换协议。只需运行以下命令:

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

使用HTTPS协议替代Git。


13
我感觉很蠢。我一直尝试在命令中使用点之前的部分,而没有想到@Sindre是告诉我们要使用git 代替 git。这些类似英语的命令真是让人头疼。 - shriek
102
如果其他人使用了这个答案,然后后来想知道如何撤销全局配置更改(就像我一样),那么方法是:git config --global --unset url."https://".insteadOf。请注意,翻译文本应保证准确传达原意,同时简化措辞以使其易于理解,但不应添加额外的解释或信息。 - ryan_effectiveui
22
您也可以省略 --global 参数,这将把配置添加到本地的 .git/config 文件中。 - agentofuser
24
在Windows机器上,全局配置文件位于用户主目录下的.gitconfig中,例如C:\Users[用户名]。但是如果未定义%HOME%,git将使用%HOMEDRIVE%,而来自bower的git则会改用%USERPROFILE%。这两个变量可能不同。在我的计算机上,一个是U:,另一个是C:\Users\myusername。因此,无论我尝试什么,bower仍然使用了git://。我花了一段时间才弄清楚这一点,所以写下来以防其他人遇到相同的情况。 - AnthonyY
2
@VincentGauthier 在Windows中,打开系统属性->高级->环境变量->系统变量->新建->添加一个名为HOME的变量,并将其值设置为所需路径。 - Nick
显示剩余11条评论

2

在@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 https://dev59.com/FGUo5IYBdhLWcg3w7S-T
    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
}

0

对我有用 git config --global url."git://".insteadOf https://


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接