-
Star
(1,216)
You must be signed in to star a gist -
Fork
(280)
You must be signed in to fork a gist
-
-
Save laispace/666dd7b27e9116faece6 to your computer and use it in GitHub Desktop.
git config --global https.proxy http://127.0.0.1:1080 | |
git config --global https.proxy https://127.0.0.1:1080 | |
git config --global --unset http.proxy | |
git config --global --unset https.proxy | |
npm config delete proxy |
实测如下, 详细见: https://gist.github.com/liuyunbin/b6b820ecca264e2768e6574dc4235763#git
# 1. http 协议
git config --global http.proxy http://192.168.68.1:7890; # 设置 http 代理
git clone https://github.com/liuyunbin/note; # 测试
git config --global --unset http.proxy; # 取消代理设置
git config --global http.proxy socks5h://192.168.68.1:7890; # 设置 socks5h 代理
git clone https://github.com/liuyunbin/note; # 测试
git config --global --unset http.proxy; # 取消代理设置
# 2. ssh 协议访问
# 2.1 windows 10 --- git-bash
在 ~/.ssh/config 中添加: --- http 代理
Host github.com
ProxyCommand connect -H 192.168.68.1:7890 %h %p
git clone [email protected]:liuyunbin/note; # 测试
在 ~/.ssh/config 中添加: --- socks 代理
Host github.com
ProxyCommand connect -S 192.168.68.1:7890 %h %p
git clone [email protected]:liuyunbin/note; # 测试
# 2.2 centos 7
在 ~/.ssh/config 中添加: --- http 代理
Host github.com
ProxyCommand nc --proxy-type http --proxy 192.168.68.1:7890 %h %p
git clone [email protected]:liuyunbin/note; # 测试
在 ~/.ssh/config 中添加: --- socks5 代理
Host github.com
ProxyCommand nc --proxy-type socks5 --proxy 192.168.68.1:7890 %h %p
git clone [email protected]:liuyunbin/note; # 测试
# 2.3 ubuntu 24.04
在 ~/.ssh/config 中添加: --- http 代理
Host github.com
ProxyCommand nc -X connect -x 192.168.68.1:7890 %h %p
git clone [email protected]:liuyunbin/note; # 测试
在 ~/.ssh/config 中添加: --- socks5 代理
Host github.com
ProxyCommand nc -X 5 -x 192.168.68.1:7890 %h %p
git clone [email protected]:liuyunbin/note; # 测试
感谢up主的这篇文章,我整理了一下思路大家也可以参考,我发现在Ubuntu系统下,git clone很快,但是MAC里面很慢 @TLovers 环境配置: Mac:OS 14.1.1. git version 2.39.3 Ubuntu: OS 22.04 git version 2.34.1,Ubuntu系统安装在Mac的虚拟机里面 VPN: ClashX,1.118.0,安装在Mac电脑上,代理端口:7890,配置如下图所示
1)验证下载速度的命令(GIT_CURL_VERBOSE 用于查看git的调试打印信息): GIT_CURL_VERBOSE=1 git clone --depth=1 --recursive --shallow-submodules [email protected]:ClickHouse/ClickHouse.git
2)在执行上面这个命令时,我发现Ubuntu下载代码很快,Mac很慢,对比了调试打印信息,发现了一些不同的地方: Ubuntu会走代理来下载代码,如下图所示:
3)然后我尝试在Mac给Git配置代理,命令如下: git config --global http.proxy http://127.0.0.1:7890 git config --global https.proxy https://127.0.0.1:7890
4)然后再次git clone,发现Mac下还是没有走代理,速度还是很慢。
5)我尝试检查代理端口是否正常启动,发现一个特别的地方,我的MAC电脑代理 可能 用的是localhost,而不是127.0.0.1
6)我再尝试在Mac给Git配置代理,命令如下: git config --global http.proxy http://localhost:7890 git config --global https.proxy https://localhost:7890
7)确认Mac上git的配置 git config --list
8)再次执行git clone,Mac现在会走代理,速度好像快起来了:
![]()
localhost和127.0.0.1不是一样的吗
前面的方法对我都不行,我的解决方法是:
- 下载 GitHub Desktop
- 打开
C:\Users\<UserName>\.gitconfig
[remote "origin"]
的proxy = http://127.0.0.1:代理端口
感谢灵神,在项目文件夹的".git\config"中添加proxy = http://127.0.0.1:代理端口
可以了
mac下 梯子ClashX 执行
git config --global http.https://git.521000.best.proxy socks5://127.0.0.1:7890
设置完成后, ~/.gitconfig文件中会增加以下条目:
[http "https://github.com"]
proxy = socks5://127.0.0.1:7890
再用https方式下载,会走梯子, 亲测有效!
mac下,仅仅设置 ~/.ssh/config 即可:
Host github.com
User git
ProxyCommand nc -v -x 127.0.0.1:7890 %h %p
thanks a lot!