为git设置代理

     0评论

文章目录[隐藏]

如果git clone报错Timeout或者ProxyError,按照以下说明设置代理就好了。

几个原则

  • 不同于环境变量http[s]_proxy,无须设置https.proxyhttp.proxy会负责所有的http[s]请求
  • git设置代理支持直接用socks5,无需先将socks5代理转http
  • 如果使用socks5,需要DNS解析也由远端执行,就使用socks5h://

设置方法

以下命令以127.0.0.1:1080为例,如不需设置全局代理,取消--global参数:

# 设置http代理 git config --global https.proxy http://127.0.0.1:1080 # 设置socks5代理 git config --global http.proxy socks5://127.0.0.1:1080 # 设置socks5代理,且远端执行DNS解析 git config --global http.proxy socks5h://127.0.0.1:1080 # 取消代理 git config --global --unset http.proxy # 如代理需认证,使用以下完整格式 git config --global http.proxy http://proxyUsername:[email protected]:port # 如果遇到[unable to access 'https://...': Unknown SSL protocol error in connection to ...:443]错误,可取消ssl验证: git config http.sslVerify false # 查看当前相关的设置: git config --get-regexp http.*

了解更多

运行git help config,可以阅读跟代理有关的部分如下:

http.proxy Override the HTTP proxy, normally configured using the http_proxy, https_proxy, and all_proxy environment variables (see curl(1)). In addition to the syntax understood by curl, it is possible to specify a proxy string with a user name but no password, in which case git will attempt to acquire one in the same way it does for other credentials. See gitcredentials(7) for more information. The syntax thus is [protocol://][user[:password]@]proxyhost[:port]. This can be overridden on a per-remote basis; see remote.<name>.proxy http.proxyAuthMethod Set the method with which to authenticate against the HTTP proxy. This only takes effect if the configured proxy string contains a user name part (i.e. is of the form [email protected] or [email protected]:port). This can be overridden on a per-remote basis; see remote.<name>.proxyAuthMethod. Both can be overridden by the GIT_HTTP_PROXY_AUTHMETHOD environment variable. Possible values are: · anyauth - Automatically pick a suitable authentication method. It is assumed that the proxy answers an unauthenticated request with a 407 status code and one or more Proxy-authenticate headers with supported authentication methods. This is the default. · basic - HTTP Basic authentication · digest - HTTP Digest authentication; this prevents the password from being transmitted to the proxy in clear text · negotiate - GSS-Negotiate authentication (compare the --negotiate option of curl(1)) · ntlm - NTLM authentication (compare the --ntlm option of curl(1))

参考资料

-- EOF --

本文最后修改于12个月前 (06-07)

差评不太行一般挺好非常不错 (No Ratings Yet)
读取中...
发表我的评论
取消评论
表情

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

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址