Week 4 Day 2 完整使用说明
📋 任务概览
设置Git Subtree,将公开项目发布到GitHub。
预计时间: 3-4小时
前置条件: GitHub账号和权限
🎯 快速开始
方式1: 自动化脚本(推荐)
# 1. 在GitHub手动创建3个仓库(见下文)
# 2. 运行自动化脚本
.\tools\setup\setup_day2.ps1 `
-SdkUrl "https://github.com/YOUR_ORG/mbe-sdk-python.git" `
-McpUrl "https://github.com/YOUR_ORG/mbe-mcp-server.git" `
-EducationUrl "https://github.com/YOUR_ORG/mbe-education.git"
# 脚本会自动:
# - 配置Git远程仓库
# - 迁移public/项目
# - 验证代码安全
# - 推送到GitHub
方式2: 手动步骤
详见 docs/guides/DAY2_GITHUB_SETUP_GUIDE.md
📝 详细步骤
Step 1: 在GitHub创建仓库
访问 https://github.com/new 创建以下仓库:
仓库1: mbe-sdk-python
Name: mbe-sdk-python
Description: Python SDK for Mises Behavior Engine
Visibility: Public
License: AGPL-3.0
Initialize: ❌ 不勾选任何选项
仓库2: mbe-mcp-server
Name: mbe-mcp-server
Description: Model Context Protocol Server for MBE
Visibility: Public
License: AGPL-3.0
Initialize: ❌ 不勾选任何选项
仓库3: mbe-education
Name: mbe-education
Description: Open-source Educational Application powered by MBE
Visibility: Public
License: AGPL-3.0
Initialize: ❌ 不勾选任何选项
重要: 创建时不要初始化README、.gitignore或LICENSE!
Step 2: 配置Git凭证(首次)
# 配置用户信息
git config user.name "Your Name"
git config user.email "your.email@example.com"
# Windows凭证助手
git config --global credential.helper wincred
# 或使用Personal Access Token
# GitHub Settings → Developer settings → Personal access tokens
# 创建token,权限勾选 repo
Step 3: 运行自动化脚本
# 完整运行(推荐首次使用)
.\tools\setup\setup_day2.ps1 `
-SdkUrl "https://github.com/YOUR_ORG/mbe-sdk-python.git" `
-McpUrl "https://github.com/YOUR_ORG/mbe-mcp-server.git" `
-EducationUrl "https://github.com/YOUR_ORG/mbe-education.git"
# 只迁移和验证,不推送(测试)
.\tools\setup\setup_day2.ps1 `
-SdkUrl "..." `
-McpUrl "..." `
-EducationUrl "..." `
-SkipPush
# 只配置远程和推送(已迁移)
.\tools\setup\setup_day2.ps1 `
-SdkUrl "..." `
-McpUrl "..." `
-EducationUrl "..." `
-SkipMigration -SkipValidation
Step 4: 验证结果
4.1 检查本地
# 查看远程仓库
git remote -v
# 查看public/目录
dir public
# 应该看到:
# public\sdk-python\
# public\mcp-server\
# public\education\
4.2 检查GitHub
访问GitHub查看3个仓库,确认代码已推送。
🔧 单独发布脚本
如果需要单独发布某个项目:
# 发布SDK
.\tools\publish\publish_sdk.ps1
# 发布MCP Server
.\tools\publish\publish_mcp.ps1
# 发布Education
.\tools\publish\publish_education.ps1
🆘 常见问题
Q1: git subtree push很慢?
A: 正常现象,Git需要重写历史。首次推送会比较慢(可能5-10分钟)。
Q2: 推送失败 - Authentication failed
A: 凭证问题,解决方法:
# 清除旧凭证
git credential-manager clear
# 重新配置
git config --global credential.helper wincred
# 再次推送,会弹出登录窗口
Q3: 推送失败 - Updates were rejected
A: 可能的原因:
- GitHub仓库已有内容 → 删除重建(不要Initialize)
- 分支名不对 → 检查是main还是master
- 权限不足 → 检查GitHub账号权限
Q4: 验证失败 - 包含私有依赖
A: 代码包含private模块引用,需要修复:
# 查看具体问题
python tools\publish\validate_public.py public\<project>
# 修复后重新验证
Q5: 能否修改某个公开项目?
A: 可以,有两种方式:
方式1: 在Monorepo中修改
# 1. 修改public/<project>/文件
# 2. 提交到Monorepo
git add public/<project>
git commit -m "update: ..."
# 3. 推送到GitHub
git subtree push --prefix=public/<project> <project-name> main
方式2: 接受GitHub PR
# 1. 有人在GitHub提交PR
# 2. Review并合并
# 3. 同步回Monorepo
git subtree pull --prefix=public/<project> <project-name> main
✅ 完成标准
- ✅ 3个GitHub仓库创建成功
- ✅ Git远程仓库配置正确
- ✅ public/目录包含3个项目
- ✅ 代码安全验证全部通过
- ✅ Git Subtree推送成功
- ✅ GitHub上能看到代码
📊 预期结果
本地目录结构
mises-behavior-engine/
├── public/
│ ├── sdk-python/ # ✅ 从opensource/迁移
│ ├── mcp-server/ # ✅ 从opensource/迁移
│ └── education/ # ✅ 从opensource/迁移
├── opensource/ # 保留(向后兼容)
├── private/ # 空(待Day 5迁移)
└── ...
Git远程配置
$ git remote -v
education https://github.com/YOUR_ORG/mbe-education.git (fetch)
education https://github.com/YOUR_ORG/mbe-education.git (push)
mcp-server https://github.com/YOUR_ORG/mbe-mcp-server.git (fetch)
mcp-server https://github.com/YOUR_ORG/mbe-mcp-server.git (push)
origin <your-private-repo> (fetch)
origin <your-private-repo> (push)
sdk-python https://github.com/YOUR_ORG/mbe-sdk-python.git (fetch)
sdk-python https://github.com/YOUR_ORG/mbe-sdk-python.git (push)
GitHub仓库
- https://github.com/YOUR_ORG/mbe-sdk-python ✅
- https://github.com/YOUR_ORG/mbe-mcp-server ✅
- https://github.com/YOUR_ORG/mbe-education ✅
🎯 下一步
Day 2完成后,继续:
- Day 3: Docker配置优化
- Day 4: CI/CD准备
- Day 5: 私有代码迁移
文档更新: 2026-02-01
预计时间: 3-4小时
难度: 中等(主要是Git Subtree较慢)