1. 环境准备
Node.js 安装
# 使用 Homebrew 安装brew install nodebrew install pnpm
# 验证安装node --versionpnpm --version
2. 创建 Astro 项目
初始化项目
pnpm dlx create-astro my-blog --template chrismwilliams/astro-theme-cactuscd my-blogpnpm installpnpm dev
3. Git 与 GitHub 配置
初始化 Git 仓库
cd my-blog # 确保在正确目录git initgit add .git commit -m "first commit"git branch -M main
关联 GitHub
git remote add origin https://github.com/username/my-blog.gitgit push -u origin main
4. 多设备管理
SSH Key 配置
# 在每台设备上生成 SSH Key
# 查看公钥内容cat ~/.ssh/id_ed25519.pub
GitHub 添加多个 SSH Key
- 访问 GitHub -> Settings -> SSH and GPG keys
- 点击 “New SSH key”
- 为每台设备的 Key 添加不同的标题(如:“MacBook Pro”、“Windows Desktop”)
- 粘贴对应设备的公钥内容
Git 全局配置
在每台设备上设置相同的 Git 配置:
# 设置用户名和邮箱git config --global user.name "Your Name"
# 建议设置默认分支名称git config --global init.defaultBranch main
工作流程
- 首次在新设备上使用:
# 克隆仓库cd my-blogpnpm install # 安装依赖
- 日常同步流程:
# 开始工作前先拉取最新代码git pull
# 完成修改后推送git add .git commit -m "update: 更新说明"git push
5. 日常维护流程
更新博客
# 拉取最新代码git pull
# 本地开发pnpm dev
# astro check 检查语法pnpm astro check
# 提交更改git add .git commit -m "update: 更新说明"git push