当前位置: 首页 > news >正文

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

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

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

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

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

[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

http://www.lryc.cn/news/358389.html

相关文章:

  • Centos7网络故障,开机之后连不上网ens33mtu 1500 qdisc noop state DOWN group default qlen 1000
  • 分析 Base64 编码和 URL 安全 Base64 编码
  • cocos 屏幕点击坐标转换为节点坐标
  • 电瓶车进电梯识别报警摄像机
  • 数据库到服务器提权
  • 【MySQL精通之路】InnoDB(9)-表和页压缩(1)-表压缩
  • 【前端】vue+element项目中select下拉框label想要显示多个值多个字段
  • 橙派探险记:开箱香橙派 AIpro 与疲劳驾驶检测的奇幻之旅
  • 云计算期末复习(1)
  • frp转发服务
  • 【主流分布式算法总结】
  • spring cloud config server源码学习(一)
  • 人脸识别——探索戴口罩对人脸识别算法的影响
  • 磁盘管理后续——盘符漂移问题解决
  • 基于GO 写的一款 GUI 工具,M3u8视频下载播放器-飞鸟视频助手
  • 关于EasyExcel导入数据时表格日期格式识别为数字问题
  • 高通Android 12/13打开省电模式宏开关
  • 2023年西安交通大学校赛(E-雪中楼)
  • 如何在vue2中使用tailwind
  • 【OrangePi AIpro】开箱初体验以及OAK深度相机测试
  • 滑动窗口模板(Java)
  • transformers.BertTokenizer入门使用
  • 快乐数-力扣
  • Git标签的使用
  • 【uni-app】Pinia 持久化
  • Flink 窗口
  • 基于大模型和RAG技术实现的开源项目
  • mac m1安装homebrew管理工具(brew命令)完整流程
  • Liunx学习随笔
  • mac中文件夹怎么显示.git隐藏文件