Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@mikicomo

This comment has been minimized.

Copy link

@mikicomo mikicomo commented Dec 20, 2015

git config --local https.proxy https://127.0.0.1:1080 我这样配置有什么问题么?为什么还是没走ss代理呢?

@itolfh

This comment has been minimized.

Copy link

@itolfh itolfh commented Jan 13, 2016

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

@chunxiao369

This comment has been minimized.

Copy link

@chunxiao369 chunxiao369 commented May 8, 2016

Thanks!

@zhuyingda

This comment has been minimized.

Copy link

@zhuyingda zhuyingda commented Sep 28, 2016

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

@tolbkni

This comment has been minimized.

Copy link

@tolbkni tolbkni commented Oct 26, 2016

@zhuyingda 显然是 https 不起作用,只有 http 起作用

@joydragon-wang

This comment has been minimized.

Copy link

@joydragon-wang joydragon-wang commented Oct 31, 2016

It works. Thank you very much.

@bit-rocket

This comment has been minimized.

Copy link

@bit-rocket bit-rocket commented Nov 6, 2016

My ubuntu server was blocked to git clone some github repo,

Do as @itolfh said,

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

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

my git works!
Thanks @itolfh

@AStogov

This comment has been minimized.

Copy link

@AStogov AStogov commented Nov 7, 2016

thanks a lot

@xuinvip

This comment has been minimized.

Copy link

@xuinvip xuinvip commented Dec 11, 2016

thanks!

@BobLiu20

This comment has been minimized.

Copy link

@BobLiu20 BobLiu20 commented Jan 11, 2017

thanks! Working for me.

@iTofu

This comment has been minimized.

Copy link

@iTofu iTofu commented Jan 13, 2017

Thank you! It works for me.

@iqiancheng

This comment has been minimized.

Copy link

@iqiancheng iqiancheng commented Feb 3, 2017

it works! thanks!

@JohnTian

This comment has been minimized.

Copy link

@JohnTian JohnTian commented Feb 11, 2017

it works! thanks a lot!

@larryli

This comment has been minimized.

Copy link

@larryli larryli commented Feb 16, 2017

👍

@CommonEra93

This comment has been minimized.

Copy link

@CommonEra93 CommonEra93 commented Mar 2, 2017

这个是http和https 代理把? 如果我想用ssh呢?

@pamzerbhu

This comment has been minimized.

Copy link

@pamzerbhu pamzerbhu commented Mar 7, 2017

it works!顶一个

@whyscience

This comment has been minimized.

Copy link

@whyscience whyscience commented Mar 14, 2017

按照

#只对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

@liuliangsir

This comment has been minimized.

Copy link

@liuliangsir liuliangsir commented Mar 16, 2017

thx~

@zhEdward

This comment has been minimized.

Copy link

@zhEdward zhEdward commented Mar 17, 2017

在天朝 使用 git clone 的正确姿势哇

@godtree94

This comment has been minimized.

Copy link

@godtree94 godtree94 commented Mar 28, 2017

现在什么都要设代理,yum npm git wget...天朝.........................................

@watsy0007

This comment has been minimized.

Copy link

@watsy0007 watsy0007 commented Mar 28, 2017

thanks @itolfh

@leetking

This comment has been minimized.

Copy link

@leetking leetking commented Mar 28, 2017

我如此设置之后clone gist同样没有被代理

git设置

[http]
    proxy = socks5://127.0.0.1:1080
[https]
    proxy = socks5://127.0.0.1:1080

本地ss5端口

$ nmap localhost
Starting Nmap 7.01 ( https://nmap.org ) at 2017-03-28 23:05 CST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000035s latency).
Not shown: 998 closed ports
PORT     STATE SERVICE
1080/tcp open  socks

Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds

ss查看开放端口信息

$ ss -tln | grep 1080
LISTEN     0      128    127.0.0.1:1080                     *:* 

我确信ss5已经打开并且能用,毕竟浏览器能用。
但是在

$ git clone https://gist.github.com/666dd7b27e9116faece6.git
正克隆到 '666dd7b27e9116faece6'...
fatal: unable to access 'https://gist.github.com/666dd7b27e9116faece6.git/': gnutls_handshake() failed: The TLS connection was non-properly terminated.

出现如上错误,我不知道是不是我的git设置问题呢。在这里提问抱歉了。我也google搜索了很久,只有在您这里提到了设置ss5。
谢谢

@Ivicelsbak

This comment has been minimized.

Copy link

@Ivicelsbak Ivicelsbak commented Apr 4, 2017

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

@dkzwm

This comment has been minimized.

@raidsan

This comment has been minimized.

Copy link

@raidsan raidsan commented Apr 21, 2017

注意: 代理地址不要加引号!
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
大部分网站下载没问题, 但是遇到 gclient 下载会出错, 去掉引号号后成功

@andydevacc

This comment has been minimized.

Copy link

@andydevacc andydevacc commented May 3, 2017

thanks for sharing.

@leetintin

This comment has been minimized.

Copy link

@leetintin leetintin commented Jun 17, 2017

thanks!LOL!

@zhangle1

This comment has been minimized.

Copy link

@zhangle1 zhangle1 commented Jun 19, 2017

问下 我想代理 git://git.com 这种开头应该怎么加 ,试了下 不行

@hippasus

This comment has been minimized.

Copy link

@hippasus hippasus commented Jun 26, 2017

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

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

@Jimmy-Z

This comment has been minimized.

Copy link

@Jimmy-Z Jimmy-Z commented Aug 3, 2017

补充两点:
1, https.proxy设置是无用的, 只需要设置http.proxy
2, socks5h://更好, 远端DNS

@Skura23

This comment has been minimized.

Copy link

@Skura23 Skura23 commented Aug 22, 2017

请问带s和不带s有什么区别

@8enet

This comment has been minimized.

Copy link

@8enet 8enet commented Sep 21, 2017

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

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

This comment has been minimized.

Copy link

@ZoeShaw101 ZoeShaw101 commented Oct 8, 2017

为什么我设置了代理还是会time out

@modifMX

This comment has been minimized.

Copy link

@modifMX modifMX commented Dec 28, 2017

为什么我设置了代理还是会time out 我也是

@erguotou520

This comment has been minimized.

Copy link

@erguotou520 erguotou520 commented Jan 4, 2018

windows 按照 itolfh 说的可以成功

@lolosssss

This comment has been minimized.

Copy link

@lolosssss lolosssss commented Jan 24, 2018

多次 set/unset 之后, 通过 git config --global -e 可以看到有好多空的 [http], [https]
screen shot 2018-01-24 at 2 08 32 pm

怎么能够不产生多余的内容?

@hbshun

This comment has been minimized.

Copy link

@hbshun hbshun commented Mar 20, 2018

thanks @itolfh

@b1ueb1ues

This comment has been minimized.

Copy link

@b1ueb1ues b1ueb1ues commented Mar 23, 2018

https.proxy 根本就不存在这个设置好吗
只有http.proxy是正确的 他负责所有的http[s]代理设置

@VOID001

This comment has been minimized.

Copy link

@VOID001 VOID001 commented Mar 29, 2018

git 是没有 https 这个 config section 的
如果想要使用SOCKS5代理的话只需要
git config --global http.proxy "socks5h://your_addr:your_port" 即可

@guclan

This comment has been minimized.

Copy link

@guclan guclan commented Apr 3, 2018

git 的 ssh 代理终于在这里找到了答案 万分感谢

@XinzeZhang

This comment has been minimized.

Copy link

@XinzeZhang XinzeZhang commented Apr 12, 2018

在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代理了。

@albb762

This comment has been minimized.

Copy link

@albb762 albb762 commented Apr 13, 2018

If it doesn't work,
git config --global -e
del empty [http], [https]

@vipzrx

This comment has been minimized.

Copy link

@vipzrx vipzrx commented Apr 17, 2018

@whyscience

按照

#只对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)
设置
速度感人!!!

git config --global --unset http.https://github.com.proxy) 多了一个 )

@Yaphatesheart

This comment has been minimized.

Copy link

@Yaphatesheart Yaphatesheart commented Apr 20, 2018

thx

@zhxengx

This comment has been minimized.

Copy link

@zhxengx zhxengx commented Apr 26, 2018

@Jimmy-Z socks5h效果提升太明显

@XxYyKk

This comment has been minimized.

Copy link

@XxYyKk XxYyKk commented May 1, 2018

为什么我还是不行啊 socks代理127.0.0.1:1080

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

https加上也不行
都是
: gnutls_handshake() failed: The TLS connection was non-properly terminated.

@leegcc

This comment has been minimized.

Copy link

@leegcc leegcc commented May 2, 2018

@XxYyKk @leetking gnutls_handshake() failed: The TLS connection was non-properly terminated. 这个问题我也遇到,但我按 https://blog.csdn.net/qq_38199832/article/details/77803645 这文章的方式解决了。不知道具体什么情况。。。

@Frederic-Zhou

This comment has been minimized.

Copy link

@Frederic-Zhou Frederic-Zhou commented Jun 5, 2018

it's work for me .
thx,@itolfh

@Mod233

This comment has been minimized.

Copy link

@Mod233 Mod233 commented Jul 4, 2018

怎么检查自己是否设置成功啊? 我感觉 git clone 的速度没有变化啊...

@Mod233

This comment has been minimized.

Copy link

@Mod233 Mod233 commented Jul 4, 2018

@whyscience 为何我设置了之后提示 Unable to receive initial SOCKS5 response.
...

@wubuwei

This comment has been minimized.

Copy link

@wubuwei wubuwei commented Jul 10, 2018

这里可能对你有帮助 https://www.jianshu.com/p/77f773f492c6

@lxq1

This comment has been minimized.

Copy link

@lxq1 lxq1 commented Jul 19, 2018

在Windows7系统下,我是用的 SSH 协议。需要在 用户根目录/.ssh/config 文件下配置,没有config的话就自行创建。

Host github.com
ProxyCommand connect -H 127.0.0.1:1080 %h 22

测试成功使用socks5

@YinAoXiong

This comment has been minimized.

Copy link

@YinAoXiong YinAoXiong commented Aug 3, 2018

原来ssh需要另外设置,现在才发现难怪https和ssh差那么多

@congliucong

This comment has been minimized.

Copy link

@congliucong congliucong commented Aug 7, 2018

已经成功~谢谢

@lllunaticer

This comment has been minimized.

Copy link

@lllunaticer lllunaticer commented Oct 17, 2018

My git works when i do as@itolfh says, thanks

@vkso

This comment has been minimized.

Copy link

@vkso vkso commented Oct 24, 2018

There are two ways to clone in GitHub.

  1. Clone with HTTPS: git clone https://github.com/xxx/xxx.git
  2. Clone with SSH: git clone git@github.com:xxx/xxx.git

If you don't set up a proxy for local SSH, cloning using SSH will not take the proxy.
If you want to use the socks5 proxy, you only need one command
git config --global http.proxy socks5://your-server:your-port
Unset proxy:
git config --global --unset http.proxy
It works in my Ubuntu 16.04.

@wangzhankun

This comment has been minimized.

Copy link

@wangzhankun wangzhankun commented Dec 3, 2018

按照

#只对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

请问
image
还是报错是为什么呀?我是校园网走ipv6

@rangercyh

This comment has been minimized.

Copy link

@rangercyh rangercyh commented Jan 31, 2019

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

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

就你的方法我成功了。。

@zzqcn

This comment has been minimized.

Copy link

@zzqcn zzqcn commented Feb 14, 2019

结合以上各位经验设置成功. 以下以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自带, 在<Git>\mingw64\bin\下面.

@nobita0522

This comment has been minimized.

Copy link

@nobita0522 nobita0522 commented Feb 26, 2019

My ubuntu server was blocked to git clone some github repo,

Do as @itolfh said,

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

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

my git works!
Thanks @itolfh

thanks

@smarxpan

This comment has been minimized.

Copy link

@smarxpan smarxpan commented Mar 3, 2019

设置代理

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

取消代理

git config --global --unset http.proxy

因为我用的是shadowsocks代理,所以上面是socks5h://, 如果用的是http代理,将socks5h改为http即可

如果仅仅想为github设置代理,可以这样:

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

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

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

windows使用:

Host github.com
User git
ProxyCommand connect -S 127.0.0.1:1080 %h %p
@lindexi

This comment has been minimized.

Copy link

@lindexi lindexi commented Mar 7, 2019

@whyscience 你的方法有用

@liuzhenyulive

This comment has been minimized.

Copy link

@liuzhenyulive liuzhenyulive commented Mar 20, 2019

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

it worked,thanks

@Skura23

This comment has been minimized.

Copy link

@Skura23 Skura23 commented Mar 30, 2019

本人结合 zzqcn 和 smarxpan两位朋友的配置最后解决了,
尤其是zzqcn 提到的

其中1086是socks5的监听端口, 这个可以配置的, 每个人不同, 在macOS上一般为1086.

也就是说如果你是用的ss的话, 那么这里的地址就是本机地址127.0.0.1, 端口就是ss在本地的端口,
windows默认是1080, mac是1086, 而我之前一直设置地址和端口是源服务器地址端口, 所以一直不行

另外一点是如果是使用git@协议的链接, 则要配置~/.ssh/config, 否则仅http/https链接代理生效, 上面都有提到

@JokeenZhang

This comment has been minimized.

Copy link

@JokeenZhang JokeenZhang commented Apr 23, 2019

取消代理也要如下命令吗?

npm config delete proxy

还是说unset就足够了?

@shouyong

This comment has been minimized.

Copy link

@shouyong shouyong commented May 17, 2019

➜  src export https_proxy=socks5://127.0.0.1:1086
➜  src export http_proxy=socks5://127.0.0.1:1086
➜  src git clone https://github.com/xxxx/xxx.git

测试可行!

@onloner2012

This comment has been minimized.

Copy link

@onloner2012 onloner2012 commented Jul 10, 2019

There are two ways to clone in GitHub.

  1. Clone with HTTPS: git clone https://github.com/xxx/xxx.git
  2. Clone with SSH: git clone git@github.com:xxx/xxx.git

If you don't set up a proxy for local SSH, cloning using SSH will not take the proxy.
If you want to use the socks5 proxy, you only need one command
git config --global HTTP.proxy socks5://your-server:your-port
Unset proxy:
git config --global --unset http.proxy
It works in my Ubuntu 16.04.

thx you so much the ,my machine is run also,iam not set SSH 😄 😄

@liloli

This comment has been minimized.

Copy link

@liloli liloli commented Jul 29, 2019

This post helps a lot, thx everyone! :)

@yangxuanx

This comment has been minimized.

Copy link

@yangxuanx yangxuanx commented Oct 9, 2019

针对archlinux 默认没有安装netcat,仓库有两个netcat,gnu和openbsd,装openbsd-netcat,就对了

sudo pacman -S openbsd-netcat
@alancprc

This comment has been minimized.

Copy link

@alancprc alancprc commented Oct 14, 2019

针对archlinux 默认没有安装netcat,仓库有两个netcat,gnu和openbsd,装openbsd-netcat,就对了

sudo pacman -S openbsd-netcat

thanks!

@baddate

This comment has been minimized.

Copy link

@baddate baddate commented Oct 15, 2019

git 是没有 https 这个 config section 的
如果想要使用SOCKS5代理的话只需要
git config --global http.proxy "socks5h://your_addr:your_port" 即可
为什么我这样设置,git push还是很慢啊

@LittleBreak

This comment has been minimized.

Copy link

@LittleBreak LittleBreak commented Oct 18, 2019

使用git@github.com:xxx.git clone时,提示

Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


应该怎么解决啊

@shouyong

This comment has been minimized.

Copy link

@shouyong shouyong commented Oct 21, 2019

使用git@github.com:xxx.git clone时,提示

Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

应该怎么解决啊

换成https开头的地址;

@devinor

This comment has been minimized.

Copy link

@devinor devinor commented Oct 22, 2019

thanks

@sanjayzzzhong

This comment has been minimized.

Copy link

@sanjayzzzhong sanjayzzzhong commented Oct 24, 2019

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

thanks

@yanxijian

This comment has been minimized.

Copy link

@yanxijian yanxijian commented Nov 6, 2019

补充两点:
1, https.proxy设置是无用的, 只需要设置http.proxy
2, socks5h://更好, 远端DNS

  1. 确实设置http.proxy就可以了 (git config --global https.proxy http://127.0.0.1:1080)
  2. 我这里设置socks5时,push会提示:The ServicePointManager does not support proxies with the socks5 scheme. 需要输入账号和密码才能push
@nepaul

This comment has been minimized.

Copy link

@nepaul nepaul commented Nov 12, 2019

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

@sanjayzzzhong

This comment has been minimized.

Copy link

@sanjayzzzhong sanjayzzzhong commented Nov 13, 2019

我个人觉得不需要单独配置git的代理, 因为之前这样子配导致我的mac上用brew总是走代理, 找了好久才发现问题
因此我个人推荐每开一终端, 需要用到代理的时候再打开终端并输入一下shell语句:

# 如果你的代理走的是sock5 用这个
export ALL_PROXY=socks5://127.0.0.1:1080

或者

# 如果你的代理走的是http 用这个
export ALL_PROXY=http://127.0.0.1:1080

这样的配置仅针对当前终端, 如果新开一个终端就没有走代理.
单独为git设置代理的话, 会在git的配置文件里添加代理, 有时候难以定位错误.
希望我的建议能够帮助到各位~

@nepaul

This comment has been minimized.

Copy link

@nepaul nepaul commented Nov 13, 2019

我个人觉得不需要单独配置git的代理, 因为之前这样子配导致我的mac上用brew总是走代理, 找了好久才发现问题
因此我个人推荐每开一终端, 需要用到代理的时候再打开终端并输入一下shell语句:

# 如果你的代理走的是sock5 用这个
export ALL_PROXY=socks5://127.0.0.1:1080

或者

# 如果你的代理走的是http 用这个
export ALL_PROXY=http://127.0.0.1:1080

这样的配置仅针对当前终端, 如果新开一个终端就没有走代理.
单独为git设置代理的话, 会在git的配置文件里添加代理, 有时候难以定位错误.
希望我的建议能够帮助到各位~

👍👍

@lucifer717

This comment has been minimized.

Copy link

@lucifer717 lucifer717 commented Nov 13, 2019

打开自己的ss客户端,看下http代理的端口,我的1087并不是1080,别被误导了

@yangruihan

This comment has been minimized.

Copy link

@yangruihan yangruihan commented Nov 22, 2019

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

为什么要加引号呢,我加了引号反而有问题,去掉引号成功了

@HarborZeng

This comment has been minimized.

Copy link

@HarborZeng HarborZeng commented Dec 7, 2019

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

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

谢谢 可以用于windows10

@HarborZeng

This comment has been minimized.

Copy link

@HarborZeng HarborZeng commented Dec 7, 2019

For those who use linux system like centos, debian or deepin, if there are problems with nc -X, you can chose connect-proxy, intorduced https://stackoverflow.com/questions/19161960/connect-with-ssh-through-a-proxy

Just use

$ sudo apt install connect-proxy -y

and then edit your ~/.ssh/config as following:

Host github.com
User git
ProxyCommand connect-proxy -S 127.0.0.1:1080 %h %p
@iSteveyang

This comment has been minimized.

Copy link

@iSteveyang iSteveyang commented Dec 21, 2019

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

大佬NB

@liuzhenyulive

This comment has been minimized.

Copy link

@liuzhenyulive liuzhenyulive commented Dec 28, 2019

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

如果这样用不了 可以试试把引号去掉,即

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

@E1sewhere

This comment has been minimized.

Copy link

@E1sewhere E1sewhere commented Jan 26, 2020

我也是,win10,本地使用的v2ray做代理:socks5端口维1079,http端口为1080,
为git设置了代理

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

然后又在gitconfig里查看,确实把代理添加好了.
git里使用命令

curl www.google.com

timeout,同时监听代理完全没有对google的请求,基本可以断定git的请求没有走代理.
用同样的方法在cmd里设置了代理,cmd可以成功访问到google.

不知道我是什么问题,我也在.ssh内添加了config文件并按评论设置了内容,依然timeout.

@sanjayzzzhong

This comment has been minimized.

Copy link

@sanjayzzzhong sanjayzzzhong commented Jan 26, 2020

我也是,win10,本地使用的v2ray做代理:socks5端口维1079,http端口为1080,
为git设置了代理

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

然后又在gitconfig里查看,确实把代理添加好了.
git里使用命令

curl www.google.com

timeout,同时监听代理完全没有对google的请求,基本可以断定git的请求没有走代理.
用同样的方法在cmd里设置了代理,cmd可以成功访问到google.

不知道我是什么问题,我也在.ssh内添加了config文件并按评论设置了内容,依然timeout.

在git里使用命令,是指用win10下的git bash那个终端吗?还是指什么?

@E1sewhere

This comment has been minimized.

Copy link

@E1sewhere E1sewhere commented Jan 29, 2020

我也是,win10,本地使用的v2ray做代理:socks5端口维1079,http端口为1080,
为git设置了代理

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

然后又在gitconfig里查看,确实把代理添加好了.
git里使用命令

curl www.google.com

timeout,同时监听代理完全没有对google的请求,基本可以断定git的请求没有走代理.
用同样的方法在cmd里设置了代理,cmd可以成功访问到google.
不知道我是什么问题,我也在.ssh内添加了config文件并按评论设置了内容,依然timeout.

在git里使用命令,是指用win10下的git bash那个终端吗?还是指什么?

git bash,已经解决,换了shocks协议,可以连上github了

@Atuna

This comment has been minimized.

Copy link

@Atuna Atuna commented Feb 17, 2020

结合以上各位经验设置成功. 以下以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\下面.

总结的很好,已经成功了,感谢!
我是用的git clone git@github.com/xxx,实际生效的命令是:

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

没有测试过但git clone https://github.com/xxx,的话应该是需要:

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

@liuweiGL

This comment has been minimized.

Copy link

@liuweiGL liuweiGL commented Mar 4, 2020

在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代理了。

👍👍👍

@chengyi

This comment has been minimized.

Copy link

@chengyi chengyi commented Mar 18, 2020

用proxychains呢🤣

@BatterToMe

This comment has been minimized.

Copy link

@BatterToMe BatterToMe commented Mar 18, 2020

http/https不行的,记得确认一下本地代理工具有没有打开http代理

@weaming

This comment has been minimized.

Copy link

@weaming weaming commented Mar 20, 2020

基于Trojan的代理需要双引号,git config --global http.proxy "socks5://127.0.0.1:1080"

说不通,这个配置是在ssh这边的,跟使用ss还是trojan没有关系

@1725636955

This comment has been minimized.

Copy link

@1725636955 1725636955 commented Mar 20, 2020

基于Trojan的代理需要双引号,git config --global http.proxy“ socks5://127.0.0.1:1080”

说不通,这个配置是在ssh这边的,跟使用ss还是trojan没有关系

单引号不行,

@qiuhaha

This comment has been minimized.

Copy link

@qiuhaha qiuhaha commented Mar 26, 2020

亲测:git config --global http.proxy 'http://127.0.0.1:1080'

@Hunu

This comment has been minimized.

Copy link

@Hunu Hunu commented Mar 28, 2020

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

太NB了,smarxpan 大神的方法解决了我数年的困扰!

git clone with ssh using Socks5 proxy: 亲测有效

@OsbertWang

This comment has been minimized.

Copy link

@OsbertWang OsbertWang commented Apr 25, 2020

仿照上面的内容写了以下配置方案,操作系统是 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

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

@gfsdcx1992

This comment has been minimized.

Copy link

@gfsdcx1992 gfsdcx1992 commented Apr 27, 2020

thx v m

@pcqpcq

This comment has been minimized.

Copy link

@pcqpcq pcqpcq commented May 11, 2020

just

git config --global http.proxy 127.0.0.1:1080
git config --global https.proxy 127.0.0.1:1080

without http:// or https://

@wo4wangle

This comment has been minimized.

Copy link

@wo4wangle wo4wangle commented May 11, 2020

多次 set/unset 之后, 通过 git config --global -e 可以看到有好多空的 [http], [https]
screen shot 2018-01-24 at 2 08 32 pm

怎么能够不产生多余的内容?
这条帮助了我,之前被覆盖了难受,到这里才能删除

@raymondzhaoy

This comment has been minimized.

Copy link

@raymondzhaoy raymondzhaoy commented Jun 4, 2020

thx

@Jade-Zeng

This comment has been minimized.

Copy link

@Jade-Zeng Jade-Zeng commented Jun 14, 2020

git config --global http.proxy http://127.0.0.1:网络设置里的端口号

git config --global https.proxy https://127.0.0.1:网络设置里的端口号

git config --global --unset http.proxy

git config --global --unset https.proxy
后面的端口号是你电脑走代理之后,在网络设置里的代理的端口号,在电脑的网络设置高级代理里点击http 或 https查看

@liuqinh2s

This comment has been minimized.

Copy link

@liuqinh2s liuqinh2s commented Jun 18, 2020

git config --local https.proxy https://127.0.0.1:1080 我这样配置有什么问题么?为什么还是没走ss代理呢?

因为git没有https.proxy这个选项,只有http.proxy,设置了这个,https流量也会走代理

@HarborZeng

This comment has been minimized.

Copy link

@HarborZeng HarborZeng commented Jun 19, 2020

仿照上面的内容写了以下配置方案,操作系统是 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

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

感谢 这个真的有用

@bao3

This comment has been minimized.

Copy link

@bao3 bao3 commented Jun 20, 2020

我无意间搜到这个,我是想说,我没有设置 git 单独的代理,而是设置 shell 的代理,这样就自动解决了 git / apt /yum 所有这些的网速问题。

另外如果使用 docker,可以通过添加 -e http_proxy=**** -e https_poryx=*** 来让 docker 特定容器支持代理。

@ghosoft

This comment has been minimized.

Copy link

@ghosoft ghosoft commented Jun 27, 2020

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!

@lfl976

This comment has been minimized.

Copy link

@lfl976 lfl976 commented Jul 10, 2020

good,Thanks

@han88829

This comment has been minimized.

Copy link

@han88829 han88829 commented Jul 20, 2020

[remote "origin"] proxy = socks5://127.0.0.1:1080
我使用v2ray,以上设置对我无用,直接修改proxy可以

@Jason-Ma-233

This comment has been minimized.

Copy link

@Jason-Ma-233 Jason-Ma-233 commented Jul 21, 2020

git最近更新了socks5的语法,去掉了引号,git config --global http.proxy socks5://127.0.0.1:10808配合V2RayN可用

@65zlui

This comment has been minimized.

Copy link

@65zlui 65zlui commented Jul 25, 2020

按照

#只对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

亲测有效

@HStarrr

This comment has been minimized.

Copy link

@HStarrr HStarrr commented Jul 30, 2020

在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代理了。

非常棒!这才是正确答案!!!

@MaxJmac

This comment has been minimized.

Copy link

@MaxJmac MaxJmac commented Aug 6, 2020

方法管用,就是端口必须改成跟ShadowSocks的Socks5端口一致

@Ashappyboy

This comment has been minimized.

Copy link

@Ashappyboy Ashappyboy commented Aug 14, 2020

git最近更新了socks5的语法,去掉了引号,git config --global http.proxy socks5://127.0.0.1:10808配合V2RayN可用
80是代理服务器开放端口;10808是v2ray本地监听端口,所有git设置这个监听端口;
image
本地这个端口在git内部设置没有意义。
image
直接编辑这个文件ok。
image
image
整体速度为proxy的速度,没有出现*m/s,有点遗憾,谁搞出来可以留言。
best wishes!

@qianjin1017

This comment has been minimized.

Copy link

@qianjin1017 qianjin1017 commented Aug 20, 2020

按照

#只对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

太棒了,亲测有效

@ijpq

This comment has been minimized.

Copy link

@ijpq 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

This comment has been minimized.

Copy link

@forliuyifei forliuyifei commented Sep 25, 2020

仿照上面的内容写了以下配置方案,操作系统是 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

This comment has been minimized.

Copy link

@isjeffcom isjeffcom commented Oct 6, 2020

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

@forliuyifei

This comment has been minimized.

Copy link

@forliuyifei forliuyifei commented Oct 22, 2020

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

git 走 Clash 代理

image

设置 npm 强制走 Clash 代理

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.