命令行模式下配置
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://stackoverflow.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
來源:簡書
簡書著作權歸作者所有,任何形式的轉載都請聯系作者獲得授權並注明出處。