Git设置和取消代理
查看当前的 Git 代理配置
要查看当前 Git 配置的代理,可以使用以下命令:
git config --global --get http.proxy
git config --global --get https.proxy
查看 Git 的所有配置信息
git config --list
临时配置 Git 代理
临时配置是指在当前终端会话中有效,关闭终端或重新打开终端后,代理设置会消失。
设置代理时,可以使用以下命令:
HTTP 代理:
git config --global http.proxy http://<proxy_server>:<port>
HTTPS 代理:
git config --global https.proxy https://<proxy_server>:<port>
其中,<proxy_server>
是代理服务器的地址,<port>
是端口号。例如,设置 HTTP 代理为 http://proxy.example.com:8080
,则可以执行:
git config --global http.proxy http://proxy.example.com:8080
设置完成后,Git 会在当前会话中通过指定的代理进行通信。
永久配置 Git 代理
永久配置是指设置后的代理将一直生效,直到你手动移除或更改配置。
可以使用以下命令来设置永久代理:
HTTP 代理:
git config --global http.proxy http://<proxy_server>:<port>
HTTPS 代理:
git config --global https.proxy https://<proxy_server>:<port>
这些设置会写入到 Git 的配置文件中,通常位于 ~/.gitconfig
文件内。你可以直接编辑该文件,手动设置代理(不过不建议直接编辑,使用 git config
命令更安全):
[http] proxy = http://<proxy_server>:<port> [https] proxy = https://<proxy_server>:<port>
取消代理配置
如果你不再需要代理,或者配置有误,可以通过以下命令移除代理设置:
移除 HTTP 代理:
git config --global --unset http.proxy
移除 HTTPS 代理:
git config --global --unset https.proxy
你也可以编辑 ~/.gitconfig
文件,手动删除 http.proxy
和 https.proxy
配置项。