种种原因,工作中总要设置各类代理,结果环境就容易乱,今天source tree无法拉取代码,就把网络代理相关的命令总结整理了下,分享给大家。
问题描述
- sourcetree中pull,报错:
git -c color.branch=false -c color.diff=false -c color.status=false -c diff.mnemonicprefix=false -c core.quotepath=false -c credential.helper=sourcetree fetch origin fatal: unable to access 'http://***:5188/szzx/p_aierp.git/': LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to 127.0.0.1:33210 Completed with errors, see above
环境描述
- MacBookPro
- 网络设置中配置了Proxies
- 会经常用到SacuraCat
- 因此.bash_profile中设置了:
export http_proxy=http://127.0.0.1:33210
export https_proxy=http://127.0.0.1:33210
解决过程
- .bash_profile中设置,
source ~/.bash_profile
对当前shell起作用 - 因此配置里去掉了代理设置,应用需要完全退出才能加载新的.bash_profile设置
# 确保完全退出,不只是关闭窗口
osascript -e 'quit app "SourceTree"'
# 检查是否还有SourceTree进程
ps aux | grep SourceTree
# 如果有,强制结束
pkill -f SourceTree
- 检查环境变量
# 查看所有环境变量
env
# 或者只查看代理相关变量
env | grep -i proxy
echo $http_proxy
echo $https_proxy
unset http_proxy
unset https_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
# or
export http_proxy=""
export https_proxy=""
# 检查可能设置代理的其他文件
cat ~/.zshrc | grep -i proxy
cat ~/.bashrc | grep -i proxy
cat ~/.profile | grep -i proxy
# 查看SourceTree进程的环境变量(需要先运行SourceTree)
ps eww -o command | grep SourceTree
经过上述过程,还是报错,因为有些命令自己有全局配置
检查git
# 查看Git是否配置了代理 git config --global --get http.proxy git config --global --get https.proxy # 如果有,取消设置 git config --global --unset http.proxy git config --global --unset https.proxy
检查系统级代理设置
```shell查看系统网络设置
networksetup -getwebproxy Wi-Fi
networksetup -getsecurewebproxy Wi-Fi如果需要关闭系统代理
networksetup -setwebproxystate Wi-Fi off
networksetup -setsecurewebproxystate Wi-Fi off
> 我遇到的问题是git的全局配置里有代理,去掉后就解决了。
> git config --global --unset http.proxy
> git config --global --unset https.proxy
### 创建干净的脚本环境
```shell
# 创建干净环境脚本
echo '#!/bin/zsh' > ~/sourcetree_clean.sh
echo 'unset http_proxy' >> ~/sourcetree_clean.sh
echo 'unset https_proxy' >> ~/sourcetree_clean.sh
echo 'unset HTTP_PROXY' >> ~/sourcetree_clean.sh
echo 'unset HTTPS_PROXY' >> ~/sourcetree_clean.sh
echo 'exec git "$@"' >> ~/sourcetree_clean.sh
chmod +x ~/sourcetree_clean.sh
# 在sourcetree中使用
/bin/zsh ~/sourcetree_clean.sh
小结
95% 的情况通过以下步骤解决:
✅ 检查并修改环境变量中代理配置
✅ 完全重启应用
✅ 清理特定应用(比如Git)代理配置:git config --global --unset http.proxy
备忘
命令 | 影响范围 | 说明 |
---|---|---|
source ~/.bash_profile |
仅当前终端 | 在当前会话中立即加载修改后的配置。 |
修改并保存 ~/.bash_profile |
未来的新终端 | 新开的 Login Shell 终端会自动应用更改。Non-Login Shell 终端则需要通过上述 source 命令或特殊配置来应用。 |