git配置代理

HTTP/HTTPS proxy

我在安装 Homebrew 时候,遇到GFW干扰无法正常访问GitHub。分析安装脚本,可以看到需要解决 git 网络联通问题。我的解决方法是采用 Squid父级socks代理 构建起 HTTP/HTTPS 代理

  • 配置 git 使用上述 HTTP/HTTPS 代理:

全局配置git使用HTTP/HTTPS代理
git config --global http.proxy http://192.168.7.9:3128

备注

当配置git使用HTTP/HTTPS代理时,会使得git采用HTTPS方式代替 ssh服务 方式来访问git仓库。我遇到一个问题是 为Pixel 4编译LineageOS 20(Android 13) 结合使用 Squid父级socks代理 同步 googlesource 仓库报错:

解决的方法是独立编译 使用OpenSSL的git

  • 配置 git 使用socks5代理:

全局配置git使用socks5代理
git config --global http.proxy 'socks5h://127.0.0.1:1080'

配置 socks5 或者 socks5h 都可以,不过 socks5h 可以使得主机名解析也通过代理

SSH proxy

  • git ssh proxy command:

git ssh proxy
export GIT_SSH_COMMAND='ssh -o ProxyCommand="nc -X 5 -x 127.0.0.1:1080 %h %p"'
  • OR use ~/.ssh/config :

git ssh proxy config
Host github.com
    HostName github.com
    User huataihuang
    IdentityFile ~/.ssh/github-ssh.key
    ProxyCommand /usr/bin/nc -X 5 -x 127.0.0.1:1080 %h %p

参考