SourceTree配合Shadowsocks完整配置教程
SourceTree 本身没有内置代理设置面板,底层完全依赖 Git 全局代理,分两种场景:HTTPS 仓库、SSH 仓库,先确认你的 SS 本地端口(默认 1080)。
一、前置准备
打开 Shadowsocks,开启本地 SOCKS5,记住端口:
SS 默认本地端口:1080
部分改版 SS/Clash:7890
保持 SS 全程开启,否则 Git 会连不上。
二、HTTPS 仓库(https://github.com/xxx.git)配置(最常用)
方法 1:命令行全局 Git SOCKS5 代理(推荐,SourceTree 自动生效)
打开 SourceTree 顶部菜单:工具 → 打开终端
输入下面两行(端口替换成你 SS 的端口):
bash
运行
# socks5:// 协议不能省略
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080
验证是否配置成功:
bash
运行
git config --global --get http.proxy
输出 socks5://127.0.0.1:1080 即成功。
取消代理(不用 SS 时执行)
bash
运行
git config --global --unset http.proxy
git config --global --unset https.proxy
三、SSH 仓库(git@github.com:xxx.git)额外配置
SSH 不走上面的 http.proxy,需要修改 SSH 配置文件:
Windows:C:\Users\你的用户名\.ssh\config
Mac:~/.ssh/config
写入内容(端口改成你的 SS 端口):
plaintext
Host github.com
HostName github.com
User git
ProxyCommand nc -x 127.0.0.1:1080 %h %p
Windows 缺少 nc 工具:安装 Git 自带的 MinGW,或使用 ncat。
四、Windows 系统全局代理兜底(SourceTree 内置更新走系统代理)
SourceTree 自身软件更新、登录界面会读取系统代理:
Windows 设置 → 网络和 Internet → 代理
手动设置代理:
SOCKS:127.0.0.1 端口 1080
Mac:系统设置 → 网络 → 高级 → 代理,勾选 SOCKS 代理填入地址。
五、常见问题排查
拉取代码超时、Failed connect to github.com:443
确认 SS 正常联网,端口号写对;
把 socks5:// 完整带上,不要只写 socks5;
SSH 仓库依旧不走代理
检查 .ssh/config 文件无中文、空格错误;
Windows 安装完整版 Git(自带 nc);
国内仓库(Gitee/GitLab 国内)也走代理很慢
仅给 GitHub 单独代理,不对全部网址生效:
bash
运行
# 只对github.com启用代理
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
切换代理端口后不生效
先取消旧代理,再重新执行配置命令。
六、一键切换脚本(Windows PowerShell)
开启代理:
powershell
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080
关闭代理:
powershell
git config --global --unset http.proxy
git config --global --unset https.proxy
评论

React 18的并发渲染确实是个重大改进,我们在项目中已经升级使用,性能提升明显!