美文网首页
GIt设置代理

GIt设置代理

作者: 陈树树go | 来源:发表于2019-07-16 11:02 被阅读0次

    GIt需要设置代理,才能正常访问github 等网站

    设置如下(可复制):

    git config --global https.proxy http://127.0.0.1:1080
    git config --global https.proxy https://127.0.0.1:1080
    git config --global http.proxy 'socks5://127.0.0.1:1080'
    git config --global https.proxy 'socks5://127.0.0.1:1080'

    代理服务器需要鉴权配置

    git config --global https.proxy https://username:password@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://stackoverflow.com/questions/6172719/escape-character-in-git-proxy-password 

    如以上示例中的配置,可以替换为:
    git config --global http.proxy http://username:abc%40123@proxy.baidu.com:8080

    Git代理取消

    git config --global --unset http.proxy
    git config --global --unset https.proxy

    Linux Git常见错误

    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

    相关文章

      网友评论

          本文标题:GIt设置代理

          本文链接:https://www.haomeiwen.com/subject/rpdzkctx.html