背景
作为开发人员,使用github.com上的代码工程作为第三方库是经常的事情。但因为特殊原因,访问不了github网站。网络上有很多方法,比如修改host方法,但可访问地址的IP不稳定。github.com的网络代理也可以用。近日出于需要配置Claude code skill(.claude.skill)需要,研究了下访问配置,经过 五一假期连续3天的测试,证明配置方法有效,现在共享出来。
一键式访问github.com脚本
请将以下脚本保存为.bat文件,以管理员身份执行。
bash
@echo off
chcp 65001
echo ======================================
echo Win10 一键修复 GitHub 无法访问
echo ======================================
echo.
:: 写入最新GitHub hosts映射
echo 正在更新 Hosts...
echo.>>C:\Windows\System32\drivers\etc\hosts
echo # GitHub Start>>C:\Windows\System32\drivers\etc\hosts
echo 140.82.112.3 github.com>>C:\Windows\System32\drivers\etc\hosts
echo 199.232.69.194 github.global.ssl.fastly.net>>C:\Windows\System32\drivers\etc\hosts
echo 185.199.108.133 raw.githubusercontent.com>>C:\Windows\System32\drivers\etc\hosts
echo 185.199.109.133 avatars.githubusercontent.com>>C:\Windows\System32\drivers\etc\hosts
echo # GitHub End>>C:\Windows\System32\drivers\etc\hosts
:: 刷新DNS缓存
echo 正在刷新DNS缓存...
ipconfig /flushdns
:: 清除Git代理(解决git clone失败)
echo 清除Git全局代理...
git config --global --unset http.proxy 2>nul
git config --global --unset https.proxy 2>nul
echo.
echo ✅ 修复完成!
echo 关闭浏览器重新打开 GitHub 即可
pause
访问效果
- github.com打开慢,1分钟左右,仓库搜索无延迟
- 代码git克隆有问题。
对于linux, 可以 使用github.com的代理:https://ghfast.top/。比如:https://ghfast.top/https://github.com/flipped-aurora/gin-vue-admin.git
对于windows , wsl中类似于linux中设置。对于windows直接克隆,有如下报错,作为遗留问题,后续再解决(你若有解决方案,请在评论区评论):fatal: unable to access 'https://github.com/flipped-aurora/gin-vue-admin.git/': getadd
rinfo() thread failed to start