设置终端代理

分辨需要设置的代理

  • HTTP 形式:

    git clone https://github.com/owner/git.git

  • SSH 形式:

    git clone git@github.com:owner/git.git

一、HTTP 形式

走 HTTP 代理

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

走 socks5 代理(如 Shadowsocks)

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

取消设置

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

二、SSH 形式

修改 ~/.ssh/config 文件(不存在则新建):

1
2
3
4
5
6
7
8
# 必须是 github.com
Host github.com
HostName github.com
User git
# 走 HTTP 代理
# ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=8080
# 走 socks5 代理(如 Shadowsocks)
# ProxyCommand nc -v -x 127.0.0.1:1080 %h %p
评论
加载中,最新评论有1分钟缓存...