Git Clone使用代理

Git 目前支持的三种协议 git://ssh:// 和 http://,其代理配置各不相同:core.gitproxy 用于 git:// 协议,http.proxy 用于 http:// 协议,ssh:// 协议的代理需要配置 ssh 的 ProxyCommand 参数。

GIT 协议的配置

建立 /path/to/socks5proxywrapper 文件,使用 https://bitbucket.org/gotoh/connect 工具进行代理的转换,各发行版一般打包为 proxy-connect 或者 connect-proxy。

#!/bin/sh
connect -S 127.0.0.1:7070 "$@"

配置 git

[core]
        gitproxy = /path/to/socks5proxywrapper

或者

export GIT_PROXY_COMMAND="/path/to/socks5proxywrapper"

SSH 协议的配置

建立 /path/to/soks5proxyssh 文件

#!/bin/sh
ssh -o ProxyCommand="/path/to/socks5proxywrapper %h %p" "$@"

配置 git 使用该 wrapper

export GIT_SSH="/path/to/socks5proxyssh“

当然也可以直接配置 ~/.ssh/config 的 ProxyCommand

HTTP 协议的配置

[http]
        #这里是因为 Git 使用 libcurl 提供 http 支持
        proxy = socks5://127.0.0.1:7070

所有协议全部使用 http 代理

在前一部分的基础上, /path/to/socks5proxywrapper 文件改为

#!/bin/sh
connect -H 192.168.1.100:8080 "$@"

HTTP 协议配置

[http]
    proxy = http://192.168.1.100:8080

针对域名启用代理

gitproxy 参数提供 * for * 结构,具体看 man git-config 的 core.gitproxy 部分。

然后再开启对特定网址的代理,在小飞机上选择“PAC”–>“ 编辑GFWList的用户规则 ”,然后回生成“user-rule.txt”文件。如果我要“github.com”走代理,那么在文件中添加

||github.com^

然后再在小飞机上面 选择“PAC”–>“ 更新PAC为GFWList”,然后去查看日志github.com就回走代理了。

You May Also Like

About the Author: ice.zhai

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注