方法一:命令行配置代理
-
配置代理 使用以下命令配置代理地址和端口号:
git config --global http.proxy http://代理地址:端口号
如果你的代理需要账号密码验证,可以使用以下命令:
git config --global http.proxy http://用户名:密码@代理地址:端口号
同时配置 HTTP 和 HTTPS 代理,可以使用以下命令:
git config --global http.proxy http://代理地址:端口号 git config --global https.proxy https://代理地址:端口号
-
取消代理 使用以下命令取消代理:
git config --global --unset http.proxy git config --global --unset https.proxy
方法二:修改配置文件
-
配置代理 打开 Git 的配置文件
~/.gitconfig
,在文件末尾添加以下内容:[http] proxy = http://代理地址:端口号 [https] proxy = https://代理地址:端口号
如果你的代理需要账号密码验证,可以使用以下内容:
[http]
proxy = http://用户名:密码@代理地址:端口号
[https]
proxy = https://用户名:密码@代理地址:端口号
-
取消代理
将 Git 配置文件
~/.gitconfig
中的[http]
和[https]
部分删除或者注释掉即可取消代理。