在使用 git push 时挂上VPN,可以按照以下步骤进行操作

节奏 2026-07-29 AstrillVPN 26 0

步骤 1: 获取VPN服务器的配置信息

  • 联系IT部门:确认VPN服务器的地址、端口、用户名和密码。
  • 获取证书:如果使用的是自签名证书,获取并安装相关的证书文件。

步骤 2: 配置git的HTTP和HTTPS代理

  • 设置HTTP代理
    git config --global http.proxy http://<VPN-Server-IP>:<Proxy-Port>
    git config --global http.proxy_port <Proxy-Port>
  • 设置HTTPS代理
    git config --global https.proxy https://<VPN-Server-IP>:<Proxy-Port>
    git config --global https.proxy_port <Proxy-Port>

步骤 3: 配置git仓库的远程地址

  • 克隆仓库:使用VPN服务器的地址克隆仓库:
    git clone https://<VPN-Server-IP>/<Repository-Path>/<Repository>.git
  • 修改远程地址:如果仓库已经克隆,可以修改远程地址:
    cd <Repository>
    git remote set-url origin https://<VPN-Server-IP>/<Repository-Path>/<Repository>.git

步骤 4: 运行git push命令

  • 推送代码:运行以下命令将代码推送到远程仓库:
    git push origin master:master

    根据需要,替换为目标分支。

步骤 5: 测试和验证

  • 测试连接:尝试克隆仓库或进行push操作,确认是否成功通过VPN连接。
    git clone https://<VPN-Server-IP>/<Repository-Path>/<Repository>.git
  • 检查日志:如果遇到问题,查看git的日志以获取更多信息:
    git -c http.proxy="http://<VPN-Server-IP>:<Proxy-Port>" -c https.proxy="https://<VPN-Server-IP>:<Proxy-Port>" push

步骤 6: 处理证书问题

  • 信任自签名证书:如果使用自签名证书,安装证书并信任:
    git config --global http.ssl-certificate.pem <证书路径>
    git config --global http.ssl-certificate-verify false

    或者在push命令中使用--ca-info选项:

    git push --ca-info https://<VPN-Server-IP>/<Repository>.git/

步骤 7: 使用SSH代理(可选)

  • 配置SSH代理
    ssh -D localhost:端口 <VPN-Server-IP>
  • git配置
    git config --global ssh.proxy localhost
    git config --global ssh.proxy-port 1234
  • 推送代码
    git push ssh://<VPN-Server-IP>:/<Repository>.git/

注意事项

  • 确认网络权限:确保VPN连接已被允许,防火墙设置正确。
  • 处理多个仓库:每个仓库可能需要单独配置远程地址。
  • 备份数据:在进行push操作前,确保数据安全,可能需要备份。

通过以上步骤,您可以在使用 git push 时挂上VPN,确保代码安全地推送到内部服务器。

在使用 git push 时挂上VPN,可以按照以下步骤进行操作

扫码添加AstrillVPN官网微信

扫码添加AstrillVPN官网微信

029-8826-4715
扫码添加AstrillVPN官网微信

扫码添加AstrillVPN官网微信

网站地图