npm获取yarn在安装依赖时 git://github.com/user/xx.git 无法访问解决方法 -- 使用 insteadOf设置git命令别名

今天在使用一个node项目时突然遇到 一个github的拉取异常,一看协议居然是git://xxx 貌似github早就不用这种格式了, 而是使用的git@github.com:xxx 这种或者https协议,解决方法:

使用insteadof设置git别名 url.<base>.insteadOfxx

bash 复制代码
# 这个命令是git别名的配置命令, 会将insteadof后面的地址替换为 url.后面的地址
git config --global url.https://github.com/.insteadOf git://github.com/

上面的命令执行后会在当前用户目录下面的 .gitconfig 文件中自动添加一下2行配置

bash 复制代码
[url "https://github.com/"]
	insteadOf = git://github.com/

这样,当我们在使用 git://github.com/ 进行克隆和拉取远程仓库时,Git会自动将其转换为 https://github.com/ 这样就成功解决了这个git://无法拉取的问题。

当然这个别名设置命令也可以解决类似git无法访问或者访问协议相关的问题。

这个别名设置命令的官方解释:

url.<base>.insteadOf

Any URL that starts with this value will be rewritten to start, instead, with <base>. In cases where some site serves a large number of repositories, and serves them with multiple access methods, and some users need to use different access methods, this feature allows people to specify any of the equivalent URLs and have Git automatically rewrite the URL to the best alternative for the particular user, even for a never-before-seen repository on the site. When more than one insteadOf strings match a given URL, the longest match is used.

Note that any protocol restrictions will be applied to the rewritten URL. If the rewrite changes the URL to use a custom protocol or remote helper, you may need to adjust the protocol.*.allow config to permit the request. In particular, protocols you expect to use for submodules must be set to always rather than the default of user. See the description of protocol.allow above.

参考文档 Git - git-config Documentation

相关推荐
wuk9985 小时前
基于MATLAB编制的锂离子电池伪二维模型
linux·windows·github
whale fall5 小时前
npm install安装的node_modules是什么
前端·npm·node.js
ai小鬼头6 小时前
AIStarter如何助力用户与创作者?Stable Diffusion一键管理教程!
后端·架构·github
天天扭码6 小时前
从图片到语音:我是如何用两大模型API打造沉浸式英语学习工具的
前端·人工智能·github
&Sinnt&8 小时前
Git 版本控制完全指南:从入门到精通
git·后端
独立开阀者_FwtCoder9 小时前
【Augment】 Augment技巧之 Rewrite Prompt(重写提示) 有神奇的魔法
前端·javascript·github
做梦都在学习前端10 小时前
发布一个monaco-editor 汉化包
前端·npm·vite
极客悟道11 小时前
巧解 Docker 镜像拉取难题:无需梯子和服务器,拉取数量无限制
后端·github
Tiny21411 小时前
多人协同开发时Git使用命令
git
独立开阀者_FwtCoder11 小时前
你用 Cursor 写公司的代码安全吗?
前端·javascript·github