问题1

  • 使用hexo d时报错fatal: unable to access
  • cd .deploy_git后运行git branch,发现只有master而没有默认的main

解决方案

  • cd .deploy_git后输入以下内容
1
2
3
4
5
cd .deploy_git
git checkout -b main # 创建 main 分支(如果不存在)
git branch -D master # 删除错误的 master 分支
git remote add origin https://github.com/your_username/your_username.github.io.git # 重新添加远程仓库(如果需要)
git push -u origin main # 推送到远程 main 分支
  • cd ..即可重新deploy

问题2

  • 用上述方法将branch调整过后仍会时而出现unable to access报错
  • 但过几分钟再试往往又好了
  • 推测为https连接问题

解决方案

  • 切换为ssh连接,ssh连接使用二进制协议,传输效率更高
  1. 生成ssh密钥(如果你还没有)
1
ssh-keygen -t ed25519 -C "your_email@example.com"

(如果系统不支持 Ed25519,可以使用 RSA:ssh-keygen -t rsa -b 4096 -C "your_email@example.com")

按提示保存密钥(默认路径为 ~/.ssh/id_ed25519 或 ~/.ssh/id_rsa)

  1. 将公钥添加到github
    • 复制公钥内容
    1
    cat ~/.ssh/id_ed25519.pub
    • 登录 GitHub,进入 Settings > SSH and GPG keys > New SSH key,将公钥粘贴并保存
  2. 修改远程仓库地址为ssh
    进入你的hexo项目根目录,将https改为ssh
1
git remote set-url origin git@github.com:username/repo.git
  1. 测试ssh连接
1
ssh -T git@github.com

如果显示 Hi username! You've successfully authenticated...,说明 SSH 配置成功。