Git为github设置代理

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

file

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

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

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 设置代理的优雅方式,希望对您有所帮助。记得要根据实际情况进行修改哦!

nvitop是一款实用、高颜值的GPU进程管理工具
使用 Acme.sh使用生成Let's Encrypt免费泛域名证书
标签:

发表我的评论

电子邮件地址不会被公开。 必填项已用*标注

75 + 70 =

ajax-loader