1 http/sock5代理

# http代理
git config --global http.proxy http://127.0.0.1:10809
git config --global https.proxy https://127.0.0.1:10809

# socks5代理
git config --global http.proxy socks5://127.0.0.1:10808
git config --global https.proxy socks5://127.0.0.1:10808


# 取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy


# 查看单个代理设置
git config --global http.proxy
git config --global https.proxy

# 查看所有设置
git config --global -l

2 git ssh协议代理

see: https://docs.github.com/en/authentication/troubleshooting-ssh/using-ssh-over-the-https-port

注意:需要将git地址中的github.com变更为ssh.github.com,如下示例

git@github.com:vuejs/vue.git --> git@ssh.github.com:vuejs/vue.git

文件C:/Users/<系统用户名>/.ssh/config中添加以下内容:

Host *
  # IdentityFile "C:/Users/Cooper/.ssh/id_rsa"
  ProxyCommand "D:/ProgramFiles/Git/mingw64/bin/connect.exe" -H 127.0.0.1:10809 %h %p
  TCPKeepAlive yes
  IdentitiesOnly yes

Host github.com
  User git
  Port 22
  Hostname github.com
Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com

说明:

  • Host: 固定
  • github.com:指定要走代理的仓库域名
  • -H: HTTP 代理
  • 在调用 ProxyCommand 时,%h 和 %p 将会被自动替换为目标主机名和 SSH 命令指定的端口( %h 和 %p 不要修改,保留原样即可)。