XuLaLa.Tech

首页客户端下载Windows 使用V2Ray 教程SSR 教程Clash 教程

Git为github设置代理

2025.04.09

如今,Git 和 GitHub 已经成为程序员工作和学习中不可缺少的重要工具,但在使用 Git 和 GitHub 这类工具的时候,可能会出现某些特殊环境导致网络无法连接的情况,此时我们就需要为 GitHub 设置代理了。

文章目录

  • 1 查看是否已经存在全局代理
  • 2 设置代理
  • 3 对代理进行身份验证
  • 4 取消代理设置
  • 5 小技巧

查看是否已经存在全局代理

首先,我们需要检查一下是否已经存在全局代理,可以通过以下方式查看:

git config --global --get http.proxy

如果已经存在全局代理,则会返回代理相关的信息。

设置代理

如果还没有设置代理,我们可以通过以下方式设置代理:

git config --global https.proxy https://proxy.example.com:8080
git config --global http.https://github.com.proxy http://127.0.0.1:7890
git config --global https.https://github.com.proxy http://127.0.0.1:7890

其中,proxy.example.com:8080 是你的代理地址和端口号,根据实际情况进行修改。

对代理进行身份验证

如果代理需要身份验证,我们可以通过以下方式设置代理用户名和密码:

git config --global http.proxyAuthMethod 'basic'
git config --global http.proxyAuthUsername <Your-Username>
git config --global http.proxyAuthPassword <Your-Password>

其中,Your-Username 和 Your-Password 分别是你的代理登录用户名和密码,根据实际情况进行修改。

取消代理设置

如果需要取消代理设置,可以通过以下方式取消代理:

git config --global --unset https.proxy

小技巧

通过SSH来配置代理,编辑~/.ssh/config文件, 新增下面配置
Host github.com
ProxyCommand connect -H 127.0.0.1:7890 %h %p   #-S为socks
HostName %h
Port 22
User git
IdentityFile  ~/.ssh/id_rsa
IdentitiesOnly yes

以上就是为 GitHub 设置代理的优雅方式,希望对您有所帮助。记得要根据实际情况进行修改哦!

© 2010-2022 XuLaLa 保留所有权利 本站由 WordPress 强力驱动
请求次数:69 次,加载用时:0.665 秒,内存占用:32.19 MB