之前mac中设置了git的代理
但是是全局的代理
导致对于gitee,git去push时,也用上了代理
导致现在问题是:
当一些代理节点问题,比如ss或ssr节点有问题时,要去更换节点,很是麻烦,无法git push了:
1 2 | ➜ SmartElectric git:(master) git push fatal: unable to access 'https://gitee.com/xxx/xxx.git/' : LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to gitee.com:443 |

所以现在希望去弄成:
- git push
- github:用代理
- 针对github用代理
- gitee:不用代理
git proxy only github
1 2 3 | ➜ ~ ls -lh .git* -rw-r--r-- 1 crifan staff 505B 1 13 22:21 .gitconfig -rw-r--r-- 1 crifan admin 13B 12 16 2015 .gitignore_global |
1 2 3 4 5 6 | [http] proxy = http: / / my.proxy.net: 8080 [https] proxy = http: / / my.proxy.net: 8443 proxy = "" |
感觉这个更适合我
目前配置值是:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | ➜ ~ cat ~ / .gitconfig [user] name = crifan email = admin@crifan.com [core] excludesfile = / Users / crifan / .gitignore_global autocrlf = input askpass = git - gui - - askpass [difftool "sourcetree" ] cmd = opendiff \ "$LOCAL\" \"$REMOTE\" path = [mergetool "sourcetree" ] cmd = / Applications / SourceTree.app / Contents / Resources / opendiff - w.sh \ "$LOCAL\" \"$REMOTE\" -ancestor \"$BASE\" -merge \"$MERGED\" trustExitCode = true [push] default = simple [http] proxy = socks5: / / 127.0 . 0.1 : 1086 [https] proxy = socks5: / / 127.0 . 0.1 : 1086 |
.gitconfig per domain
1 2 3 4 5 6 7 8 9 10 11 | ; Proxy settings [core] gitproxy = proxy - command for kernel.org gitproxy = default - proxy ; for all the rest ; HTTP [http] sslVerify sslVerify = false cookieFile = / tmp / cookie.txt |
此处希望自己的一些github的git仓库:
- https://github.com/crifan/scientific_network_summary.git
- https://github.com/crifan/android_app_security_crack.git
- https://github.com/crifan/http_restful_api.git
用代理
而gitee
不用代理
所以此处暂时只需要去设置gitee的地址,代理为空
编辑:
1 | ➜ ~ vi ~/.gitconfig |
为:
1 2 3 4 5 6 7 8 | [http] proxy = socks5: / / 127.0 . 0.1 : 1086 [https] proxy = socks5: / / 127.0 . 0.1 : 1086 proxy = "" proxy = "" |
然后试试效果
结果问题依旧。
.gitconfig http proxy
参考:
去试试是否match
1 2 3 | ➜ ~ git config --bool --get-urlmatch https.proxy https: //gitee .com /TonglingSmartElectric/SmartElectric .git/ ➜ ~ git config --get-urlmatch https https: //gitee .com/ ➜ ~ git config --get-urlmatch http https: //gitee .com/ |
也确定对不对
看起来貌似也是对的,没问题啊
1 | git config --global --get-regexp http.* |
结果:
1 2 3 4 | http.proxy socks5: //127 .0.0.1:1086 https.proxy socks5: //127 .0.0.1:1086 http.http: //gitee .com/.proxy https.https: //gitee .com/.proxy |
git config http proxy specific url
把proxy改为空,而不是 空字符串:
1 2 3 4 5 6 7 8 | [http] proxy = socks5: / / 127.0 . 0.1 : 1086 [https] proxy = socks5: / / 127.0 . 0.1 : 1086 proxy = proxy = |
当前git版本:
1 2 | ➜ ~ git --version git version 2.20.1 (Apple Git-117) |
是2.20.1
1 2 3 4 5 6 7 8 9 10 11 12 | * The "http.*" variables can now be specified per URL that the configuration applies. For example, [http] sslVerify = true sslVerify = false would flip http.sslVerify off only when talking to that specified site. |
按道理是支持单独url设置的
结果:
问题依旧。
实在不行,去试试no_proxy
换成完整git仓库地址
1 2 3 4 5 6 7 8 | [http] proxy = socks5: / / 127.0 . 0.1 : 1086 [https] proxy = socks5: / / 127.0 . 0.1 : 1086 proxy = proxy = |
结果:
真的就可以了。。。

那去改为带*的,看看是否支持
或许不对,或许是:
之前http的proxy的地址,也应该是https
1 2 3 4 5 6 7 8 | [http] proxy = socks5: / / 127.0 . 0.1 : 1086 [https] proxy = socks5: / / 127.0 . 0.1 : 1086 proxy = proxy = |
结果:
真的是可以的:

【总结】
此处,针对不的git仓库,即url,配置不同的代理
比如:
- github.com:用代理
- 本地的ss的代理:socks5://127.0.0.1:1086
- gitee.com:不用代理
- proxy设置为空
具体做法是:
编辑git的全局配置
1 | vi ~/.gitconfig |
改为:
1 2 3 4 5 6 7 8 | [http] proxy = socks5: / / 127.0 . 0.1 : 1086 [https] proxy = socks5: / / 127.0 . 0.1 : 1086 proxy = proxy = |
核心配置是
1 2 | [http] proxy = socks5: //127 .0.0.1:1086 |
使得:所有url,所有git仓库,包括github,都能用代理
和
1 2 | proxy = |
使得:对于特定的gitee.com的git仓库,不用代理。
【后记】
git https.proxy
基本上可以确定:
其实git的proxy的配置:
- 只有 http.proxy
- 对应.gitconfig中[http]的proxy
- 但没有 https.proxy
- 很多人都以为对于 https的地址,比如 https://github.com,https://gitee.com/ 也是http的proxy,需要对应的https的proxy
- 其实没有https.proxy这个配置参数
所以去掉https的proxy
1 2 3 4 |
结果:也是可以的。
对于gitee.com的git仓库,是可以忽略代理的。
【后记2】
后来去提交自己gitbook到github仓库上,本地仓库的确是用了代理了,速度不错:
