设置命令
#设置使用http/https本地代理
git config --global https.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
#取消http/https本地代理
git config --global --unset http.proxy
git config --global --unset https.prox
以上方式如果还不能解决,可以再次尝试设置sock5代理:
git config --global http.proxy ‘socks5://127.0.0.1:1080’
git config --global https.proxy ‘socks5://127.0.0.1:1080’
如果只针对GitHub设置代理,则用如下命令:
#只对github.com
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
对于使用 ssh:// 协议的,可以配置socks5代理,在 ~/.ssh/config 文件内容后面添加几行:
Host github.com
User git
ProxyCommand connect -S 127.0.0.1:1080 %h %p
适用场景
- hexo等发布到GitHub时失败,错误提示:“xx time out”
- 更新GitHub仓库无响应 $ git push ssh:
connect to host github.com port 22: Network is unreachable fatal:
The remote end hung up unexpectedly