Skip to content

Instantly share code, notes, and snippets.

@ehlxr
Forked from chuyik/README.md
Last active April 16, 2020 03:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehlxr/610471c4a5d95b83dad8a4fa417b3229 to your computer and use it in GitHub Desktop.
Save ehlxr/610471c4a5d95b83dad8a4fa417b3229 to your computer and use it in GitHub Desktop.
macOS 给 Git(Github) 设置代理(HTTP/SSH)

分辨需要设置的代理

一、HTTP 形式

走 HTTP 代理

# git config --global http.proxy "http://127.0.0.1:1081"
# git config --global https.proxy "http://127.0.0.1:1081"

# 针对 github 进行配置,让 github 走本地代理,其他的保持不变;
git config --global http.https://github.com.proxy https://127.0.0.1:1081
git config --global https.https://github.com.proxy https://127.0.0.1:1081

走 socks5 代理(如 Shadowsocks)

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

# 针对 github 进行配置,让 github 走本地代理,其他的保持不变;
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080

取消设置

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

git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy

二、SSH 形式

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

# 必须是 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment