Git设置代理

起因:最近想研究一下React-Native,于是进行了初步的学习,但是居然卡在了入门pop install安装失败...

报错原因

image-20220808110220500

由图可知,是因为国内防火墙对GitHub仓库进行了阻断/污染,导致依赖包下载失败

开启V2Ray后依旧会下载失败,是因为V2ray无法自动代理Git(全局代理也是这样)

解决方法

手动设置Git代理即可

## 端口号根据自己的端口来
##添加代理(HTTP|HTTPS协议)
git config --global http.proxy http://127.0.0.1:1081
git config --global https.proxy https://127.0.0.1:1081
##使用socks5代理的
git config --global http.proxy socks5://127.0.0.1:1081
git config --global https.proxy socks5://127.0.0.1:1081

#只对github.com使用代理,其他仓库不走代理
git config --global http.https://github.com.proxy socks5://127.0.0.1:1081
git config --global https.https://github.com.proxy socks5://127.0.0.1:1081

## 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy

#SSH协议
##对于使用git@协议的,可以配置socks5代理
##在~/.ssh/config 文件后面添加几行,没有可以新建一个
##socks5
Host github.com
User git
ProxyCommand connect -S 127.0.0.1:1081 %h %p

##http || https
Host github.com
User git
ProxyCommand connect -H 127.0.0.1:1081 %h %p
微信扫一扫体验微信小程序
Last modification:August 8, 2022
If you think my article is useful to you, please feel free to appreciate