git clone 分 HTTP 形式和 SSH 形式,而这两种形式的都可以走  http  代理和  socks5  代理这两种代理

SSH 形式

ssh 形式:git clone git@github.com/xxx/xxx.git。在 ~/.ssh/config 文件添加下面内容 (http 代理或者 socks5 代理):

1
2
3
4
5
6
7
8
# GitHub
Host github.com
HostName github.com
IdentityFile ~/.ssh/id_rsa.github # 这个根据自己的私钥名确定
# 走 HTTP 代理
# ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=7890
# 走 socks5 代理(如 Shadowsocks)
# ProxyCommand nc -v -x 127.0.0.1:7890 %h %p

HTTP 形式

http 形式:git clone https://github.com/xxx/xxx.git

配置 git 全局代理

通过命令配置:

  1. http 代理

    1
    2
    git config --global http.proxy "http://127.0.0.1:7890"
    git config --global https.proxy "http://127.0.0.1:7890"

  2. socks5 代理

    1
    2
    git config --global http.proxy "socks5://127.0.0.1:7890"
    git config --global https.proxy "socks5://127.0.0.1:7890"

  3. 取消代理

    1
    2
    git config --global --unset http.proxy
    git config --global --unset https.proxy

通过 git 配置文件配置:

vim ~/.gitconfig 加入:

1
2
3
4
[http]
proxy = socks5://127.0.0.1:7890
[https]
proxy = socks5://127.0.0.1:7890

配置终端临时代理

1
2
3
# proxy list
alias proxy='export all_proxy=socks5://127.0.0.1:7890'
alias unproxy='unset all_proxy'