一、Github DNS污染
GitHub Hosts
Hosts List
复制
completed
#Github Hosts Start
#Update Time: 2025/1/27 14:42:16
#Project: githubhosts.xuanyuan.me
#Daily updated GitHub hosts for better access
140.82.113.25 alive.github.com
140.82.113.26 live.github.com
185.199.111.154 github.githubassets.com
140.82.112.21 central.github.com
185.199.108.133 desktop.githubusercontent.com
185.199.108.133 camo.githubusercontent.com
185.199.108.133 github.map.fastly.net
146.75.121.194 github.global.ssl.fastly.net
140.82.121.3 gist.github.com
185.199.108.153 github.io
140.82.121.4 github.com
192.0.66.2 github.blog
140.82.121.5 api.github.com
185.199.108.133 raw.githubusercontent.com
185.199.108.133 user-images.githubusercontent.com
185.199.111.133 favicons.githubusercontent.com
185.199.110.133 avatars5.githubusercontent.com
185.199.108.133 avatars4.githubusercontent.com
185.199.110.133 avatars3.githubusercontent.com
185.199.108.133 avatars2.githubusercontent.com
185.199.111.133 avatars1.githubusercontent.com
185.199.108.133 avatars0.githubusercontent.com
185.199.108.133 avatars.githubusercontent.com
140.82.121.9 codeload.github.com
52.217.138.129 github-cloud.s3.amazonaws.com
3.5.28.197 github-com.s3.amazonaws.com
54.231.233.241 github-production-release-asset-2e65be.s3.amazonaws.com
3.5.29.138 github-production-user-asset-6210df.s3.amazonaws.com
3.5.0.126 github-production-repository-file-5c1aeb.s3.amazonaws.com
185.199.110.153 githubstatus.com
140.82.113.18 github.community
51.137.3.17 github.dev
140.82.112.22 collector.github.com
13.107.42.16 pipelines.actions.githubusercontent.com
185.199.108.133 media.githubusercontent.com
185.199.110.133 cloud.githubusercontent.com
185.199.109.133 objects.githubusercontent.com
#Github Hosts End
Hosts 修改方法
修改 hosts 文件
hosts 文件在不同系统位置不一,详情如下:
- Windows 系统:C:\Windows\System32\drivers\etc\hosts
- Mac(苹果电脑)系统:/etc/hosts
- Linux 系统:/etc/hosts
修改方法,把上面 Hosts List 的内容复制到文本末尾:
- Windows 使用记事本
- Linux、Mac 使用 Root 权限:sudo vi /etc/hosts
激活生效
大部分情况下是直接生效,如未生效可尝试下面的办法,刷新 DNS:
- Windows:在 CMD 窗口输入:
ipconfig /flushdns
- Mac 命令:
sudo killall -HUP mDNSResponder
- Linux 命令:
sudo nscd restart
常见问题
为什么要修改hosts文件?
修改hosts文件可以帮助绕过DNS问题,改善GitHub的连接,特别是在GitHub访问受限或速度较慢的地区。
GitHub hosts多久更新一次?
本网站的GitHub hosts每天更新,确保您始终使用最新的IP地址。
修改hosts文件安全吗?
是的,修改hosts文件是安全的。但请确保只添加可信的条目,并在修改前备份原始文件。
修改后的hosts文件不起作用怎么办?
如果修改后的hosts文件出现问题,您可以随时恢复原始文件或删除添加的条目。
实现原理
获取 GitHub Hosts IP 的方法可以通过以下步骤实现:
方法 1:使用 DNS 查询工具
- 打开命令行工具(Windows 的 cmd 或者 macOS/Linux 的 Terminal)。
- 运行以下命令查询 GitHub 的 IP 地址:
- Windows:
nslookup github.com
- macOS/Linux:
dig github.com
- 结果中会显示 GitHub 的当前 IP 地址。
方法 2:通过公共 DNS 服务
一些公共的 DNS 查询工具可以直接在网页上查找,比如:
- Google Public DNS
- Cloudflare DNS Resolver
直接输入 github.com 查看其解析的 IP 地址。
方法 3:利用在线 IP 检测工具
访问以下网站之一:
- IP Address
- Ping.pe
- ViewDNS
输入 github.com,这些工具会显示域名的详细解析信息。
方法 4:查询 GitHub 官方 IP 段
- 访问 GitHub 官方文档:GitHub 的 IP 地址。
- 查看其最新的 IP 地址范围,通常这些是 GitHub 服务的代理地址。
方法 5:手动配置 Hosts 文件
如果需要将 IP 地址写入 hosts 文件以加速访问:
- Windows: 修改 C:\Windows\System32\drivers\etc\hosts 文件。
- macOS/Linux: 修改 /etc/hosts 文件。
示例配置(请根据查询结果更新 IP 地址):
140.82.114.3 github.com 140.82.113.4 assets.github.com
保存后,刷新 DNS 缓存:
⚠️ 注意事项:
- IP 地址可能会随时间变化,确保定期更新。
- 如果频繁需要使用 IP,考虑使用稳定的代理或 DNS 加速服务,例如 Cloudflare 或阿里云解析服务。
- 使用正确的工具和配置,以避免网络访问中断。
2. Pull 命令问题
2.1. 先前没有共同的分支无法合并
C:\Users\Administrator\AppData\Local\Arduino15\RemoteSketchbook\ArduinoCloud\78686059\ESP01S-SwithingMaid> git pull remote main --force From https://github.com/CRScienceTechnology/SwithingMaid
- branch main -> FETCH_HEAD fatal: refusing to merge unrelated histories
根据你提供的错误信息,git pull remote main --force
操作失败的原因是本地仓库和远程仓库的历史记录被认为是“不相关的历史”(unrelated histories)。以下是解决此问题的步骤:
1. 问题原因
- 当本地仓库和远程仓库没有共同的祖先提交时,Git 默认会拒绝合并这些不相关的历史记录。
- 这种情况通常发生在以下场景:
- 本地仓库是从头初始化的,而远程仓库已经有自己的提交历史。
- 或者本地仓库和远程仓库分别从不同的初始状态创建。
2. 解决方法
方法一:强制合并不相关的历史
使用 --allow-unrelated-histories
参数允许 Git 合并不相关的历史记录:
bash
git pull origin main --allow-unrelated-histories
步骤:
执行上述命令后,Git 会尝试将远程分支的更改合并到本地分支。
如果存在冲突,Git 会提示你手动解决冲突。
解决冲突后,完成合并:
bash
git add <冲突文件> git commit
方法二:重新克隆远程仓库
如果本地仓库的内容较少或可以丢弃,可以直接重新克隆远程仓库:
bash
# 删除当前目录(备份重要文件) rm -rf C:\Users\Administrator\AppData\Local\Arduino15\RemoteSketchbook\ArduinoCloud\78686059\ESP01S-SwithingMaid # 重新克隆远程仓库 git clone https://github.com/CRScienceTechnology/SwithingMaid.git
步骤:
- 删除当前本地仓库目录(确保备份重要文件)。
- 使用
git clone
命令重新获取远程仓库内容。
- 将本地修改的内容重新应用到新克隆的仓库中。
方法三:手动合并远程内容
如果你希望保留本地仓库的历史记录,可以手动将远程内容合并到本地:
bash
# 添加远程仓库为新的远程分支 git remote add origin https://github.com/CRScienceTechnology/SwithingMaid.git # 获取远程分支内容 git fetch origin # 合并远程分支到本地分支 git merge origin/main --allow-unrelated-histories
步骤:
- 添加远程仓库地址。
- 使用
git fetch
获取远程分支的内容。
- 使用
git merge
将远程分支合并到本地分支,并允许合并不相关的历史记录。
3. 预防类似问题
为了避免类似问题,建议在初始化本地仓库时直接从远程仓库克隆:
bash
git clone <远程仓库地址>
这样可以确保本地仓库和远程仓库有共同的祖先提交。
通过以上方法,你应该能够成功解决 fatal: refusing to merge unrelated histories
的问题。
3.Push 命令问题
2.1 OpenSSL 443问题
- 【问题描述】
终端输入git push -f --set-upstream Remote main
/ git push --set-upstream
弹出消息报错窗口如下
OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443
【问题分析】
- 原因一:没有为 Git 命令配置代理,以 Clash 为代理但是忘记为 Git 命令设置代理服务了
- 原因二:Git 代理设置协议等有误区
【方案尝试】
输入命令git config --global -l
,观察自己的 git 代理设置中使用的是什么协议,如下方情况使用的是 http ,也可以改成是 Socket5 协议。
user.name=lotuscl
user.email=16******82@qq.com
credential.https://gitee.com.provider=generic
http.https://github.com.proxy=http://127.0.0.1:7890
输入如下命令为 Git 配置全局代理(前提是你 Clash 配置好了)
git config --global http.https://github.com.proxy http://127.0.0.1:7890
git config --global https.https://github.com.proxy https://127.0.0.1:7890
【方案验证】
- 输入命令:
git push -f --set-upstream Remote main
,终端输出如下

注意:这个命令中的 Remote(该项目所在的远程仓库在本地git中的命名) 和 main (该项目的本体仓库名)