一、背景

在使用git进行clone的时候,发现浏览器可以正常打开,而命令行却总是超时,怀疑是git代理的问题。于是尝试了各种办法后,终于通过设置git代理解决了。

如以下地址:GitHub - CocoaPods/Specs: The CocoaPods Master Repo,开发设备已经通过代理设置,浏览器可以正常访问github。但git命令行访问会出现如下错误:

致命错误:无法访问 'https://github.com/CocoaPods/Specs.git/':Failed to connect to github.com port 443 after 75047 ms: Couldn't connect to server

二、解决方法

通过git config进行设置,如下

git config --global https.proxy 'socks5://127.0.0.1:1086'
git config --global http.proxy 'socks5://127.0.0.1:1086'

再次执行依赖的安装如下

至此,解决了依赖下载慢或者超时问题。

三、其他

如果想把git的代理移除,执行如下操作

git config --global --unset https.proxy
git config --global --unset http.proxy

设置http代理

hongbozhao@bogon ~ % git config --global https.proxy 127.0.0.1:1087
hongbozhao@bogon ~ % git config --global http.proxy 127.0.0.1:1087 

指定某网址使用代理

#使用socks5代理(推荐)
git config --global http.https://github.com.proxy socks5://127.0.0.1:1086
git config --global https.https://github.com.proxy socks5://127.0.0.1:1086
#使用http代理(不推荐)
git config --global http.https://github.com.proxy http://127.0.0.1:1087
git config --global https.https://github.com.proxy https://127.0.0.1:1087

Logo

更多推荐