GIT 设置 socks5 代理
GIT 设置 socks5 代理

Http代理,容易受到DNS污染;建议Socks5代理

http/https 模式

全局代理

设置

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

取消

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

github.com 专用代理

设置

git config --global http.https://github.com.proxy socks5://127.0.0.1:1080

{home}/.gitconfig 文件变化

[http "https://github.com"]
	proxy = socks5://127.0.0.1:1080

取消

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

ssh 模式

windows

新增 或者 修改 此文件 {home}/.ssh/config

文件内容-添加

# Read more about SSH config files: https://linux.die.net/man/5/ssh_config

Host github.com
  User git
  Hostname github.com
  Port 22
  TCPKeepAlive yes
  # 注意修改为您的 SSH 密钥文件的路径
  IdentityFile "C:\Users\{you_name}\.ssh\id_rsa"
  # 需要通过MINGW64的shell执行git命令
  ProxyCommand connect -S 127.0.0.1:1080 -a none %h %p

windows 环境下必须通过 MINGW64git bash shell 才能成功,否则找不到 connect 程序

MacOS

新增 或者 修改 此文件 {home}/.ssh/config

文件内容-添加

# Read more about SSH config files: https://linux.die.net/man/5/ssh_config

Host github.com
   User git
   HostName github.com
   # socks5
   ProxyCommand nc -v -x 127.0.0.1:1080 %h %p

http/https模式 socks5代理 参考文档

macos ssh模式 socks5代理 参考文档

http 代理 参考文档


最后修改于 2024-03-02

此篇文章的评论功能已经停用。