关于无法拉取github的一些事

前言

受限于所在的环境,很多情况下都需要从 github 无法获取源码。

方法一:配置和测试443端口是否可用

因为ssh默认是使用22端口,然后github是支持443端口,如果22不可用,可以尝试443端口

ssh -T -p 443 git@ssh.github.com

出现如下文字则成功
可用文案

编辑config文件,如果没有则创建即可

linux 默认配置文件在 ~/.ssh/configwindow 默认在 C:/用户名目录/.ssh/config

# 加入
Host github.com
Hostname ssh.github.com
Port 443

测试链接是否成功

ssh -T git@github.com

成功文案

方法二:通用科学方法

编辑config文件,如果没有则创建即可

linux 默认配置文件在 ~/.ssh/configwindow 默认在 C:/用户名目录/.ssh/config

window

# github
Host github.com
HostName github.com
#ProxyCommand connect -S 127.0.0.1:1111 -4 %h %p # socks4
#ProxyCommand connect -S 127.0.0.1:2222 %h %p # socks5
ProxyCommand connect -H 127.0.0.1:3333 %h %p # http

自行更改对应的IP和端口

Linux

安装对应的命令 socatnc

Host github.com
HostName github.com
User git
# 走 HTTP 代理
# ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=1111
# 走 socks5 代理 (亲测并未成功)
# ProxyCommand nc -v -x 127.0.0.1:2222 %h %p

自行更改对应的IP和端口

方法三:配置 .gitconfig

该方法只适用于 http 方式拉取

[http "http://github.com/"]
  proxy = socks5://127.0.0.1:1111
[https "https://github.com/"]
  proxy = socks5://127.0.0.1:1111

方法四:配置 host

最后修改:2023 年 01 月 07 日 09 : 02 AM

发表评论