Git仅针对github设置代理 、取消代理方法

代码同步使用git管理,有些内容是国内的资源,有些是GitHub上的资源。

所以需要只对Github上的内容进行设置代理,相关方法如下:

A. 设置代理:

//sock5代理 (推荐)
git config --global http.https://github.com.proxy socks5://127.0.0.1:7890
git config --global https.https://github.com.proxy socks5://127.0.0.1:7890

//或者 http & https 代理
git config --global http.https://github.com.proxy 127.0.0.1:7890
git config --global https.https://github.com.proxy 127.0.0.1:7890


 

B. 取消代理:

当不需要使用代理时,通过以下命令取消之前设置的代理。

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

 

C. 查看代理:

查看全部的配置
$ git config -l --global
core.autocrlf=true
user.name=xxxx
user.email=ou.leiqi@163.com
http.https://github.com.proxy=socks5://127.0.0.1:7890
https.https://github.com.proxy=socks5://127.0.0.1:7890

仅查看github的代理配置
git config --global --get http.https://github.com.proxy
git config --global --get https.https://github.com.proxy

 

D. 直接修改对应的配置文件

文件位置: C:\Users\千古八方\.gitconfig  内容如下:

[core]
	autocrlf = true
[user]
	name = lsw
	email = ou.leiqi@163.com
[https "https://github.com"]
	proxy = socks5://127.0.0.1:7890
[http "https://github.com"]
	proxy = socks5://127.0.0.1:7890

本文仅针对GitHub进行设置代理,若要对所有的git请求使用代理, 删除所有命令里的【https://github.com】即可。

评论列表: