Skip to content

Instantly share code, notes, and snippets.

@laispace
Last active April 17, 2025 13:18
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
@ijpq
Copy link

ijpq commented Sep 11, 2020

git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'

work

@forliuyifei
Copy link

仿照上面的内容写了以下配置方案,操作系统是 win 10,代理用 SSR,端口 1080。
先设置了

git config --global http.https://github.com.proxy socks5h://127.0.0.1:1080

接着用

git config --global --get http.https://github.com.proxy

得到反馈

socks5h://127.0.0.1:1080

说明设置成功。
下面在用户文件夹的 .ssh 中建立 config 文件,内容为

ProxyCommand connect -S 127.0.0.1:1080 -a none %h %p

Host github.com
  User git
  Port 22
  Hostname github.com
  IdentityFile "C:\Users\****\.ssh\id_rsa"
  TCPKeepAlive yes
  ServerAliveInterval 600
  IPQoS=throughput
  ServerAliveCountMax 120

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  IdentityFile "C:\Users\****\.ssh\id_rsa"
  TCPKeepAlive yes
  ServerAliveInterval 600
  IPQoS=throughput
  ServerAliveCountMax 120

注意****要换成用户自己的名称。
此配置单参考这里这里

显示:

socks5h://127.0.0.1:1080

可还是特别慢, 开了全局ssr, 端口也是1080

@isjeffcom
Copy link

isjeffcom commented Oct 6, 2020

https是没用的,无论复制的地址有没有SSL加密,改http.proxy就行了。顺便蹲一个办法,有没有办法只设置单次clone使用代理?

@forliuyifei
Copy link

感觉没上网工具的日子会越来越难过😭

git 走 Clash 代理

image

设置 npm 强制走 Clash 代理

@likemby
Copy link

likemby commented Nov 11, 2020

为什么设置成这样的代理就能加速啊,这是什么原理?

@aszswaz
Copy link

aszswaz commented Nov 27, 2020

请问一下,我只设置了git config --global https而没设置git config --global http的时候,clone一个google的git仓库依然不行,后来加上了http的设置才可以,我也是ss代理代理都和你们一样,有人知道这是为什么吗?我的clone仓库url是https的啊,但还是需要把http和https代理都挂上才可以吗?
没有单独的https代理协议,https也是属于http的代理协议的一部分

@Ron2014
Copy link

Ron2014 commented Feb 17, 2021

在windows上,在Git Bash里设置

ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p

会报错的,提示:

/usr/bin/bash: line 0: exec: nc: not found

因为这个bash是不带netcat的,也就找到不到nc命令。
在win10上,有的msysgit版本集成了connect工具,所以在windows上,可以把ssh的config文件设置为:

Host github.com
ProxyCommand connect -S 127.0.0.1:1080 %h %p

就可以给ssh加socks代理了。

I have done with these in ~/.ssh/config

Host github.com
	HostName github.com
	User git
	# socks5 need: pacman -S mingw-w64-x86_64-connect mingw-w64-i686-connect
	ProxyCommand connect -S 127.0.0.1:2801 %h %p

Thanks you all..

$ git clone git@github.com:testerSunShine/12306.git
Cloning into '12306'...
remote: Enumerating objects: 2730, done.
fatal: index-pack failed(468/2730), 8.00 MiB | 3.82 MiB/s
client_loop: send disconnect: Broken pipe
fetch-pack: unexpected disconnect while reading sideband packet

@jun-jing
Copy link

jun-jing commented Mar 3, 2021

Thanks, it helps.

@edw4rdyao
Copy link

is slower 😫

@BoBoooooo
Copy link

nice job . worked!

@yveshield
Copy link

结合以上各位经验设置成功. 以下以macOS为准.

  1. https访问
    仅为github.com设置socks5代理(推荐这种方式, 公司内网就不用设代理了, 多此一举):
    git config --global http.https://github.com.proxy socks5://127.0.0.1:1086
    其中1086是socks5的监听端口, 这个可以配置的, 每个人不同, 在macOS上一般为1086.
    设置完成后, ~/.gitconfig文件中会增加以下条目:

    [http "https://github.com"]
        proxy = socks5://127.0.0.1:1086
    
  2. ssh访问
    需要修改~/.ssh/config文件, 没有的话新建一个. 同样仅为github.com设置代理:

    Host github.com
        User git
        ProxyCommand nc -v -x 127.0.0.1:1086 %h %p
    

    如果是在Windows下, 则需要个性%home%.ssh\config, 其中内容类似于:

    Host github.com
        User git
        ProxyCommand connect -S 127.0.0.1:1086 %h %p
    

    这里-S表示使用socks5代理, 如果是http代理则为-H. connect工具git自带, 在\mingw64\bin\下面.

worked.

@JYShaw
Copy link

JYShaw commented Apr 22, 2021

对于使用git@协议的,可以配置socks5代理
在~/.ssh/config 文件后面添加几行,没有可以新建一个

Host github.com
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p

Works for me! Thanks

@lsdark2
Copy link

lsdark2 commented May 18, 2021

thanks my git works.
my proxy tool is clash.
git config --global http.proxy 'socks5://127.0.0.1:your local proxy port

@baijianruoliorz
Copy link

git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'

works for me, Thank you!

God now i can't solve it...

@hu-qi
Copy link

hu-qi commented Jun 11, 2021

Good job!

@gqqnbig
Copy link

gqqnbig commented Jun 26, 2021

quotes are required.

@penn201500
Copy link

按照

#只对github.com
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080

#取消代理
git config --global --unset http.https://github.com.proxy)

设置
速度感人!!!
selection_001

great!!!

@xpalive
Copy link

xpalive commented Aug 2, 2021

我的代理环境在另外一个电脑上,使用的是clash
本机与代理机器在同一网段上。

配置如下

  • ~/.gitconfig 配置如下
#对所有请求代理 方案1
[http]
    proxy = socks5://192.168.10.120:7890
#只对github.com 方案2
[http "https://github.com"]
    proxy = socks5://192.168.10.120:7890

请问下,为什么我设置了域名匹配反而不能走代理了,有人知道为什么么?(方案1可以走代理,方案2不能走代理)

  • ~/.ssh/conf 配置如下
Host github.com
  ProxyCommand nc -v -x 192.168.10.120:7890 %h %p

这样配置不能走代理反而会生成一个以代理地址为名称的文件(文件名为:192.168.10.120:7890)

我想通过统一的代理机器代理我应该怎么做,谢谢

@HuangHongRui
Copy link

HuangHongRui commented Aug 4, 2021

Thx.. :)

git config --global http.proxy 'socks5://127.0.0.1:1086'

Or:

  1. input:
    git config --global -e
  2. input:
[http]
	proxy = socks5://127.0.0.1:1086
[https]
	proxy = socks5://127.0.0.1:1086

@sxsx2yzyz
Copy link

github

git config --global https.proxy socks5://127.0.0.1:1086 mac上有用,谢谢

@newpost
Copy link

newpost commented Nov 10, 2021

能否在git clone的时候临时设置代理呢 比如: git clone ssh:xxxxx.git --proxy url:port ?不胜感激

@ddzzhen
Copy link

ddzzhen commented Nov 13, 2021

It helps, thanks a lot.

@inkss
Copy link

inkss commented Nov 19, 2021

# 只对 github.com
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080

@WJie12
Copy link

WJie12 commented Nov 27, 2021

@zhangle1 使用 git@xxoo.com 这种方式,是用的 SSH 协议。需要在 ~/.ssh/config 目录下配置

Host xxoo.com(改成你的站点) ProxyCommand connect -H 127.0.0.1:1080 %h %p

It works for me! thx!

Windows + ssh

@gogomarine
Copy link

可以了解一下 proxychains4 ,可以增长寿命。

Copy link

ghost commented Dec 15, 2021

仓库代码,通过SSH的方式,确实得设置ssh代理,没想到一个小小的代理都有这么多门道。。。。还得感叹富强不易

@qaqland
Copy link

qaqland commented Jan 27, 2022

谢谢!!!

@ssdemajia
Copy link

最新的git不能加单引号,比如v2rayNG可以这么配置 git config --global http.proxy socks5://127.0.0.1:10808

@wewindy
Copy link

wewindy commented Feb 23, 2022

目前在 Windows 10 上使用 Clash

git config --global http.proxy socks5://127.0.0.1:7890
git config --global https.proxy socks5://127.0.0.1:7890

如果只想对某个地址进行代理,比如对 github.com 代理,就这样:

git config --global http.https://github.com.proxy socks5://127.0.0.1:7890

参考了 @xpalive 的方式,SSH 还得看完全文

@Gump8
Copy link

Gump8 commented Apr 25, 2022

我亲测可以:

  1. clone: git clone -c http.proxy="127.0.0.1:xxxx" https://github.com/Gump8/xxxx.git
  2. fetch upstream: git -c http.proxy="127.0.0.1:xxxx" fetch upstream
    *注意: fetch 后面不能 -c,clone 是可以的

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