最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】mac中git push只对github用代理而对gitee不用代理

Mac crifan 1546浏览 0评论
之前mac中设置了git的代理
但是是全局的代理
导致对于gitee,git去push时,也用上了代理
导致现在问题是:
当一些代理节点问题,比如ss或ssr节点有问题时,要去更换节点,很是麻烦,无法git push了:
➜  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
Configure Git to use a proxy
Use Proxy for Git/GitHub
github – Only use a proxy for certain git urls/domains? – Stack Overflow
➜  ~ 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
github – Only use a proxy for certain git urls/domains? – Stack Overflow
[http]
    proxy = http://my.proxy.net:8080
[https]
    proxy = http://my.proxy.net:8443
[http "http://my.internalgitserver.com/"]
    proxy = ""
感觉这个更适合我
目前配置值是:
➜  ~ cat ~/.gitconfig
[user]
    name = crifan
    email = [email protected]
[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
config: parse http.<url>.<variable> using urlmatch · git/git@6a56993
.gitconfig per domain
Git – git-config Documentation
; Proxy settings
[core]
     gitproxy=proxy-command for kernel.org
     gitproxy=default-proxy ; for all the rest

; HTTP
[http]
     sslVerify
[http "https://weak.example.com"]
     sslVerify = false
     cookieFile = /tmp/cookie.txt
此处希望自己的一些github的git仓库:
用代理
而gitee
不用代理
所以此处暂时只需要去设置gitee的地址,代理为空
编辑:
➜  ~ vi ~/.gitconfig
为:
[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 = ""
然后试试效果
结果问题依旧。
.gitconfig http proxy
Git Config | Backlog
参考:
github – Only use a proxy for certain git urls/domains? – Stack Overflow
去试试是否match
➜  ~ 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/
也确定对不对
Configure Git to use a proxy
看起来貌似也是对的,没问题啊
git config --global --get-regexp http.*
结果:
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
How can i exclude hostnames for using the default-proxy in git? – Super User
把proxy改为空,而不是 空字符串:
[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版本:
➜  ~ git --version
git version 2.20.1 (Apple Git-117)
是2.20.1
git/1.8.5.txt at bb80ee09974667a1db6bbc5e33574ed869b76a88 · git/git
* The "http.*" variables can now be specified per URL that the
   configuration applies.  For example,


   [http]
       sslVerify = true
   [http "https://weak.example.com/"]
       sslVerify = false


   would flip http.sslVerify off only when talking to that specified
   site.
按道理是支持单独url设置的
结果:
问题依旧。
http – Git proxy bypass – Stack Overflow
Exclude hosts or domains with git proxy – Stack Overflow
实在不行,去试试no_proxy
github – Only use a proxy for certain git urls/domains? – Stack Overflow
换成完整git仓库地址
[http]
    proxy = socks5://127.0.0.1:1086
[https]
    proxy = socks5://127.0.0.1:1086
[http "https://gitee.com/TonglingSmartElectric/SmartElectric.git/"]
    proxy =
[https "https://gitee.com/TonglingSmartElectric/SmartElectric.git/"]
    proxy =
结果:
真的就可以了。。。
那去改为带*的,看看是否支持
或许不对,或许是:
之前http的proxy的地址,也应该是https
[http]
    proxy = socks5://127.0.0.1:1086
[https]
    proxy = socks5://127.0.0.1:1086
[http "https://gitee.com/"]
    proxy =
[https "https://gitee.com/"]
    proxy =
结果:
真的是可以的:
【总结】
此处,针对不的git仓库,即url,配置不同的代理
比如:
  • github.com:用代理
    • 本地的ss的代理:socks5://127.0.0.1:1086
  • gitee.com:不用代理
    • proxy设置为空
具体做法是:
编辑git的全局配置
vi ~/.gitconfig
改为:
[http]
    proxy = socks5://127.0.0.1:1086
[https]
    proxy = socks5://127.0.0.1:1086
[http "https://gitee.com/"]
    proxy =
[https "https://gitee.com/"]
    proxy =
核心配置是
[http]
    proxy = socks5://127.0.0.1:1086
使得:所有url,所有git仓库,包括github,都能用代理
[http "https://gitee.com/"]
    proxy =
使得:对于特定的gitee.com的git仓库,不用代理。
【后记】
git  https.proxy
Git Config | Backlog
Git – git-config Documentation
基本上可以确定:
其实git的proxy的配置:
  • 只有 http.proxy
    • 对应.gitconfig中[http]的proxy
  • 但没有 https.proxy
    • 很多人都以为对于 https的地址,比如 https://github.com,https://gitee.com/ 也是http的proxy,需要对应的https的proxy
      • 其实没有https.proxy这个配置参数
所以去掉https的proxy
[http]
    proxy = socks5://127.0.0.1:1086
[http "https://gitee.com/"]
    proxy =
结果:也是可以的。
对于gitee.com的git仓库,是可以忽略代理的。
【后记2】
后来去提交自己gitbook到github仓库上,本地仓库的确是用了代理了,速度不错:

转载请注明:在路上 » 【已解决】mac中git push只对github用代理而对gitee不用代理

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.185 seconds, using 22.10MB memory