git代理配置

时间:2023-03-10 05:49:17
git代理配置

命令行模式下配置

git config --global https.proxy https://proxyuser:proxypassword@ip/域名:port

git config --global http.proxy http://proxyuser:proxypassword@ip/域名:port

示例:

假设某人在百度工作,公司代理服务器是(proxy.baidu.com),端口是(8080),代理配置如下

1、代理服务器需要鉴权配置

git config --global https.proxy https://username:password@proxy.baidu.com:8080

2、代理服务器不需要鉴权配置

git config --global https.proxy https://proxy.baidu.com:8080

密码中特殊字符处理

如果密码中有@等特殊字符,会出错,比如

git config --global http.proxy http://username:abc@123@proxy.baidu.com:8080

解析时会从第一个@解析,提示@123@proxyhk.huawei.com找不到,此时要对其中的特殊符号进行处理,使用百分比编码(Percent-encoding)对特殊字符进行转换,转换列表如下:

! --> %21    # --> %23    $ --> %24    & --> %26    ' --> %27

( --> %28    ) --> %29    * --> %2A    + --> %2B    , --> %2C

/ --> %2F    : --> %3A    ; --> %3B    = --> %3D    ? --> %3F

@ --> %40    [ --> %5B    ] --> %5D

参考资料:http://*.com/questions/6172719/escape-character-in-git-proxy-password

如以上示例中的配置,可以替换为:

git config --global http.proxy http://username:abc%40123@proxy.baidu.com:8080

配置成功后,主要的功能就打通了,接下来就可以克隆github的代码了。

常见错误

1、克隆失败,提示:server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none

解决方法:

export GIT_SSL_NO_VERIFY=1

git config --global http.sslverify false

2、提示:GnuTLS recv error (-9): A TLS packet with unexpected length was received

error: RPC failed; result=56

解决方法:

配置以下三条命令

export GIT_TRACE_PACKET=1

export GIT_TRACE=1

export GIT_CURL_VERBOSE=1

3、以上命令还不生效,则祭出大杀器

此问题为git中依赖gnutls的bug,需要对将git中的gnutls强制替换为openssl,重新编译即可

解决方案:http://askubuntu.com/questions/186847/error-gnutls-handshake-failed-when-connecting-to-https-servers/187199#187199

作者:泡芙掠夺者
链接:https://www.jianshu.com/p/27365d2542d7
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。