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
1.3 检查当前git 全局设置
git config --global -l
用上面的命令可以查看git的全部设置,查看验证设置代理与取消代理的结果,如果是设置代理成功,则列表输出会有 http.proxy=,https.proxy=等开头的行;如果取消代理成功,则 http.proxy=,https.proxy=等开头的行将不会出现再列表输出中。
例如,我执行如上命令输出如下:
core.autocrlf=false
core.filemode=false
branch.autosetuprebase=always
http.sslverify=false
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
注意:git的任何全局设置都可以用 git config --global --unset 来删除,例如(基于如上输出)执行如下命令行:
git config --global --unset filter.lfs.process
git config --global --unset filter.lfs.clean
将删除 filter.lfs.process 与 filter.lfs.clean 开头的行。
二、通过修改配置文件方式(方法二)
Windows 里假设当前用户是Administrator,则修改的配置文件路径为:
C:\Users\Administrator\.gitconfig
Linux里,编辑文件: ~/.gitconfig
用任何文本编辑器,打开如上文件,修改文本内容如下:
[https]
proxy = 'socks5://127.0.0.1:1080'
[http]
proxy = 'socks5://127.0.0.1:1080'