git设置代理的方式如下,Windows 与 Linux通用。任选如下方法的一种即可。
一、通过命令行(方法一)
1.1 设置代理
假设代理服务器的配置为:Socks5 代理,端口为1080,地址为:127.0.0.1,则直接在命令行输入如下命令:
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
如果用http代理,则输入的命令如下:
git config --global https.proxy http://127.0.0.1:10800
git config --global https.proxy https://127.0.0.1:10800
如果代理服务器在其它主机上,例如在 192.168.1.122:8118 机器上运行代理服务程序,则输入如下
git config --global https.proxy http://192.168.1.122:8118
git config --global https.proxy https://192.168.1.122:8118
1.2 取消代理设置
如果用代理下载完毕,永不着代理了,可以取消代理,命令如下:
git config --global --unset http.proxy
git config --global --unset https.proxy
二、通过修改配置文件方式(方法二)
Windows 里假设当前用户是Administrator,则修改的配置文件路径为:
C:\Users\Administrator\.gitconfig
Linux里,编辑文件: ~/.gitconfig
用任何文本编辑器,打开如上文件,修改文本内容如下:
[https]
proxy = 'socks5://127.0.0.1:1080'
[http]
proxy = 'socks5://127.0.0.1:1080'