配置 Git 插件使用代理,有几种方法可以实现:
方法一:通过 Git 全局配置代理(推荐)
在终端中执行以下命令:
1 2 3 4 5 6 7 8 9 10
| git config --global http.proxy http://127.0.0.1:7897 git config --global https.proxy http://127.0.0.1:7897
git config --global http.proxy http://127.0.0.1:7897 git config --global https.proxy http://127.0.0.1:7897
git config --global --list | grep proxy
|
方法二:为特定仓库配置代理
如果只想为 Obsidian 仓库设置代理,进入仓库目录后执行:
1 2 3
| cd /path/to/your/obsidian/vault git config http.proxy http://127.0.0.1:7897 git config https.proxy http://127.0.0.1:7897
|
方法三:通过环境变量(临时方案)
创建启动脚本,在启动 Obsidian 前设置环境变量:
1 2 3 4 5 6
|
export http_proxy=http://127.0.0.1:7897 export https_proxy=http://127.0.0.1:7897
open /Applications/Obsidian.app
|
方法四:优化 alias
将您的 alias 扩展为更完整的功能:
1 2 3 4
| alias proxyon='export http_proxy=http://127.0.0.1:7897 https_proxy=http://127.0.0.1:7897; git config --global http.proxy http://127.0.0.1:7897; git config --global https.proxy http://127.0.0.1:7897' alias proxyoff='unset http_proxy https_proxy; git config --global --unset http.proxy; git config --global --unset https.proxy' alias proxyinfo='echo "HTTP Proxy: $http_proxy"; echo "HTTPS Proxy: $https_proxy"; git config --global --get http.proxy; git config --global --get https.proxy'
|
方法五:验证代理是否生效
配置完成后,可以通过以下命令测试:
1 2 3 4 5
| git clone https://github.com/username/test-repo.git
curl -I --proxy http://127.0.0.1:7897 https://github.com
|
注意事项
- 端口号确认:确保
7897 代理软件的实际端口 - 代理协议:根据您的代理类型,可能需要使用
socks5:// 而不是 http:// - 排除内网地址:如果需要访问内网 Git 仓库,可以设置排除规则:
1 2
| git config --global http.proxy http://127.0.0.1:7897 git config --global http."https://github.com".proxy ""
|
推荐使用方法一和二,因为 Git 插件会直接读取 Git 的配置,这样设置后 Git 插件就会自动使用代理进行网络操作。