Powershell中给Git设置代理

为了方便我们使用快捷命令:

1
notepad $PROFILE

如果报错:

image-20260701113242077

我们就先执行:

1
New-Item -Path (Split-Path $PROFILE) -ItemType Directory -Force

接下来在文档中输入:

1
2
3
4
5
6
7
8
9
10
11
12
13
# 开启git代理
function gp-on {
git config --global http.proxy socks5://127.0.0.1:17890
git config --global https.proxy socks5://127.0.0.1:17890
Write-Host "Git VPN is open"
}

# 关闭git代理
function gp-off {
git config --global --unset http.proxy
git config --global --unset https.proxy
Write-Host "Git VPN is close"
}

然后回到Powershell中:

1
. $PROFILE

无编译错误


使用:

1
2
gp-on   # 开启代理
gp-off # 关闭代理