跳到主要内容

Git 设置代理

小林
后端开发工程师, 专注Go开发、微服务和云原生

用了这么久 Git 不知道使用代理需要主动设置, 直到今天死活推不上代码到 GitHub 😂

princess.png

添加全局代理

git config --global http.proxy "http://127.0.0.1:7890"
git config --global https.proxy "http://127.0.0.1:7890"
提示

Windows 系统用双引号, Linux 系统要用单引号

验证代理设置

git config --global --get http.proxy
git config --global --get https.proxy

取消代理

git config --global --unset http.proxy
git config --global --unset https.proxy

临时绕过代理

unset http_proxy
unset https_proxy

在命令中临时指定代理

git -c http.proxy="http://127.0.0.1:7890" clone https://github.com/user/repo.git

参考