优化Github体验

我个人习惯将代码放到Github上,但是由于众所周知的原因服务器拉取代码经常超时各种问题,这里分享一下的解决方案

优化Github体验

我个人习惯将代码放到Github上,但是由于众所周知的原因服务器拉取代码经常超时各种问题,这里分享一下的解决方案,(注意这不适合生产环境,不能保证稳定性)。

【灵感来源】https://github.com/ineo6/hosts

下载并导入Hosts文件

wget https://raw.githubusercontent.com/frankwuzp/github-host/main/hosts -O hosts.temp
# 无法使用选择giee源或者下载了传上去。

cat /etc/hosts >> hosts.temp
mv hosts hosts.bak
mv hosts.temp /etc/hosts
# 追加Hosts并备份。

编写脚本,自动替换

#! /bin/bash
curl https://raw.githubusercontent.com/frankwuzp/github-host/main/hosts > /etc/hosts
cat /etc/hosts.bak >> /etc/hosts

配置执行权限。

chmod +x update-hosts.sh

配置定时任务,每日自动拉取最新的Hosts

crontab -e
30 4 * * * /root/tool/github-hosts/update.sh
# 每天4点半执行更新

同样的方式也适用Windows,在Windows上可以使用计划任务配置自动执行更新。

结束