提升github网站访问与clone速度

1.github访问

众所周知的原因,国内访问github是个老大难问题。经常访问不了,或者访问速度很慢,或者从github上面clone项目很慢,经常被搞得痛不欲生…

2.设置代理

为了方便访问github,可以采用配置代理的方式。
对于http或者https协议,可以如下设置

//设置全局代理
//http
git config --global https.proxy http://127.0.0.1:1080
//https
git config --global https.proxy https://127.0.0.1:1080
//使用socks5代理的 例如ss,ssr 1080是windows下ss的默认代理端口,mac下不同,或者有自定义的,根据自己的改
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080

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

//取消全局代理
git config --global --unset http.proxy
git config --global --unset https.proxy

对于ssh协议,可以如下设置

//在~/.ssh/config 文件后面添加几行,没有可以新建一个
//socks5
Host github.com
User git
ProxyCommand connect -S 127.0.0.1:1080 %h %p

//http || https
Host github.com
User git
ProxyCommand connect -H 127.0.0.1:1080 %h %p

3.shell终端配置

想让终端走代理那么只需在 ~/.bashrc 或 ~/.zshrc 文件中,直接写入以下内容并保存:

alias setproxy="export ALL_PROXY=socks5://127.0.0.1:1080"
alias unsetproxy="unset ALL_PROXY"
alias ip="curl -i http://ip.cn"

利用终端下载资源时,先执行 setproxy 命令,结束后执行 unsetproxy 命令如果终端提示 command not found: setproxy,说明配置没有生效,执行一下 source ~/.bashrc 或 source ~/.zshrc 即可。

猜你喜欢

转载自blog.csdn.net/bitcarmanlee/article/details/115035433