GIt设置代理

GIt设置代理

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

posted @   michaelchengjl  阅读(420)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
点击右上角即可分享
微信分享提示