Git 集成
自动同步提交和 Pull Request,为 AI 助手提供代码变更上下文。GitHub 动态直接显示在任务卡片和详情视图中。
工作原理
Git 集成通过 GitHub Webhook 自动捕获你的每一次提交和 PR。配置完成后无需任何额外操作——正常工作,历史记录自动保存。
一次性配置(5 分钟)
连接仓库并在 GitHub 中配置 Webhook。每个仓库只需配置一次,Claude 会引导你完成。
永久自动同步
来自任何终端、VS Code 或 GitHub 网页的每次 push 都会自动保存,无需任何操作。
工作流程
After Setup:
You (any terminal) GitHub ContextForge
│ │ │
│ git push │ │
│───────────────────────▶│ │
│ │ │
│ │ webhook (automatic) │
│ │───────────────────────────▶│
│ │ │
│ │ │ Saves commit
│ │ │ to memory
│ │ │
Later, ask Claude:
"What commits did I make this week?"
"What changed in the auth module?"
"Show me recent PRs"配置指南
连接 GitHub 仓库有两种方式:使用仪表盘(推荐)或通过 MCP 命令。
通过仪表盘连接(推荐)
前往账户设置
点击 "Connect Repository"
输入仓库 URL(如 owner/repo 或完整 GitHub URL)并选择项目。
在 GitHub 中配置 Webhook
对话框会显示 Payload URL 和 Secret,附带复制按钮。点击链接可直接跳转到仓库的 Webhook 设置页面。
激活
在 GitHub 添加 Webhook 后,点击 "I've Added the Webhook - Activate" 开始同步。
通过 MCP 命令连接
第 1 步:让 Claude 连接你的仓库
"Connect my GitHub repo https://github.com/username/my-project"
第 2 步:在 GitHub 中配置 Webhook
Claude 会提供 Payload URL 和 Secret。在仓库的 Settings → Webhooks 中添加。
第 3 步:激活 Webhook
"Activate the webhook for my repo"
Webhook 配置详情
在 GitHub 添加 Webhook 时,使用以下设置:
- 进入仓库 → Settings → Webhooks → Add webhook
- 粘贴 ContextForge 提供的 Payload URL
- 将 Content type 设置为
application/json - 粘贴 ContextForge 提供的 Secret
- 在 "Which events would you like to trigger this webhook?" 中选择 Let me select individual events
- 勾选 Pushes 和 Pull requests
- 点击 Add webhook
提示:GitHub 会发送一个 "ping" 验证 Webhook。若配置成功,你会看到绿色对勾。
完成!一切就绪
从现在起,你的每一次 git push(来自任何终端、VS Code 或 GitHub)都会自动保存到你的记忆中,无需额外步骤。
任务中的 GitHub 动态
当提交和 PR 通过 issue:<short_id> 标签关联到任务时,它们会直接显示在仪表盘中:
任务卡片上的标识
任务卡片和列表行显示带有关联提交和 PR 数量的 GitHub 图标,在网格视图和列表视图中均可见。
详情视图区块
打开任务后会显示"GitHub Activity"区块,包含所有关联提交和 PR 的完整列表,含 SHA、作者及外部链接。
关联机制:MCP Webhook 处理提交时,若提交信息或 PR 引用了某个任务,会自动为 Knowledge Item 添加 issue:<short_id> 标签。这些标签将提交与界面中的任务关联起来。
管理已连接的仓库
可在仪表盘的 Account 页面管理已连接的仓库。GitHub Repositories 区块显示所有已连接仓库及其同步状态。
激活 / 暂停同步
无需删除仓库即可开启或关闭 Webhook 同步。
查看 Webhook 信息
随时访问 Webhook URL 和 Secret,以更新 GitHub 配置。
在 GitHub 中打开
快速跳转到 GitHub 上的仓库。
断开连接
移除仓库及所有已同步数据。记得同时在 GitHub 中删除 Webhook。
查询 Git 历史
提交开始保存后,你可以向 Claude 询问项目历史:
# 近期动态
"What commits did I make today?"
# 按功能查询
"Show commits related to authentication"
# PR 历史
"What PRs were merged this week?"
# 摘要
"Summarize changes in the last sprint"
导入已有历史
Webhook 仅捕获配置后的新提交。如需导入已有提交,请使用手动同步:
# 导入最近 50 条提交
"Sync the last 50 commits from my repo"
注意:手动同步私有仓库需要 GitHub Token。Webhook 无需 Token,因为 GitHub 直接推送数据。
捕获的内容
提交(Commits)
- 提交信息
- 作者名称与邮箱
- 时间戳
- SHA 哈希值
- 新增/修改/删除的文件
- 提交类型(feat、fix、docs 等)
Pull Requests
- PR 标题与描述
- 作者
- 状态(opened、merged、closed)
- 源分支与目标分支
- 标签
- 提交数量与变更数量
MCP 工具参考
memory_git_connect连接 GitHub 仓库,开始跟踪提交和 PR。
| 参数 | 类型 | 描述 |
|---|---|---|
| repo_url | string | GitHub URL 或 owner/repo 格式 |
| space_id | string? | 目标 Space(未指定时创建 "Git" Space) |
memory_git_activate在 GitHub 配置 Webhook 后,激活或停用该 Webhook。
| 参数 | 类型 | 描述 |
|---|---|---|
| repo | string | owner/repo 格式的仓库名 |
| active | boolean | true 为激活,false 为停用 |
memory_git_sync手动同步已有提交和 PR(私有仓库需要 GitHub Token)。
| 参数 | 类型 | 描述 |
|---|---|---|
| repo | string | owner/repo 格式的仓库名 |
| sync_type | string? | "commits"、"prs" 或 "all"(默认) |
| limit | number? | 最多同步条数(1-100,默认:30) |
memory_git_commits列出已同步到记忆的提交。
| 参数 | 类型 | 描述 |
|---|---|---|
| repo | string? | 按仓库筛选(可选) |
| limit | number? | 最多返回结果数(默认:50) |
memory_git_prs列出已同步到记忆的 Pull Request。
| 参数 | 类型 | 描述 |
|---|---|---|
| repo | string? | 按仓库筛选(可选) |
| limit | number? | 最多返回结果数(默认:50) |
memory_git_list列出所有已连接的 GitHub 仓库。
memory_git_disconnect断开仓库连接并停止同步。
| 参数 | 类型 | 描述 |
|---|---|---|
| repo | string | owner/repo 格式的仓库名 |
使用场景
"上个迭代我们改了什么?"
Claude 搜索已同步提交,汇总近期变更
"谁在负责认证模块?"
查找与特定功能或文件相关的提交和 PR
"当时为什么选择这个方案?"
PR 描述通常包含决策依据和背景信息
"生成 v2.0 的发布说明"
自动汇总版本间的变更内容
故障排查
GitHub 显示 Webhook "failed"
检查 Webhook URL 和 Secret 是否与提供的完全一致,Secret 区分大小写。
push 后提交未出现
使用 memory_git_list 验证 Webhook 是否已激活,状态应为 "active"。
手动同步返回 404
私有仓库的手动同步需要 GitHub Token。Webhook 无需 Token,因为 GitHub 直接推送数据。