Skip to content

Instantly share code, notes, and snippets.

@laispace
Last active June 25, 2024 07:28
Show Gist options
  • Save laispace/666dd7b27e9116faece6 to your computer and use it in GitHub Desktop.
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
@liyiersan
Copy link

win10系统,结合前面几位老哥的,在config文件中加入这几句: Host github.com User git ProxyCommand connect -S 127.0.0.1:7891 %h %p

测试有效,我也用是的Clash,最开始打开System Proxy(系统全局代理)都没用。 我的git不知道什么版本的,config文件的路径是C:\Program Files\Git\etc\ssh\ssh_config,用记事本打开然后加上上面三句就可以了,注意改一下端口跟你clash中的端口一致,我的是7891

太感谢了

@sakulali
Copy link

sakulali commented Apr 24, 2024

感谢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,配置如下图所示
image

1)验证下载速度的命令(GIT_CURL_VERBOSE 用于查看git的调试打印信息):
GIT_CURL_VERBOSE=1 git clone --depth=1 --recursive --shallow-submodules git@github.com:ClickHouse/ClickHouse.git

2)在执行上面这个命令时,我发现Ubuntu下载代码很快,Mac很慢,对比了调试打印信息,发现了一些不同的地方:
Ubuntu会走代理来下载代码,如下图所示:
image

Mac里面Git好像没有走代理,如下图所示:
image

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
image

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
image

8)再次执行git clone,Mac现在会走代理,速度好像快起来了:

image

@pengyinghao
Copy link

Mac 的ssh 有办法吗? 我试了上面的还是不行哇

可以试试ssh使用443端口
To set this in your SSH configuration file, edit the file at ~/.ssh/config, and add this section:

Host github.com
    Hostname ssh.github.com
    Port 443
    User git

然后正常clone、pull都可以了

救了命了 老哥6666
这个是配在hosts 中吗

@Joeland4
Copy link

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

可以!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment