git 协议使用 http 代理

通常来说,我们会使用 http/https 协议来访问 git 库,但是有些开源代码里引用的第三方模块的 URL 可能是 git 协议的,比如 qemu 最新的代码引用的都是类似 git://git.qemu.org/seabios.git 这样的 URL,导致常用的 export http_proxy/https_proxy 不再适用,通过 core.gitproxy 配置项可以让 git 使用 http 代理:

~# vi /usr/bin/gitproxy
#!/bin/bash

PROXY=http://10.123.234.123:456

proxy_addr=$(echo -e $PROXY | cut -d: -f2 | cut -c3-)
proxy_port=$(echo -e $PROXY | cut -d: -f3)

exec socat STDIO PROXY:$proxy_addr:$1:$2,proxyport=$proxy_port
~$ sudo chmod +x /usr/bin/gitproxy
~$ git config --global core.gitproxy gitproxy

socat 的使用可以参考:socat 基础操作


最后修改于 2019-01-25