gitbutler-stacks
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitButler Stacks
GitButler 栈
Dependent branches → anchor-based stacking → reviewable chunks.
<when_to_use>
- Sequential dependencies (e.g., refactor → API → frontend)
- Large features broken into reviewable chunks
- Granular code review (approve/merge early phases independently)
- Post-hoc stack organization after exploratory coding
NOT for: independent parallel features (use virtual branches), projects using Graphite stacking
</when_to_use>
依赖分支 → 基于锚点的堆叠 → 可评审的代码块。
<when_to_use>
- 顺序依赖(例如:重构 → API → 前端)
- 大型功能拆分为可评审的小块
- 精细化代码评审(可独立批准/合并早期阶段)
- 探索性编码后进行事后栈组织
不适用场景:独立并行功能(使用虚拟分支)、使用Graphite堆叠的项目
</when_to_use>
Stacked vs Virtual Branches
堆叠分支 vs 虚拟分支
| Type | Use Case | Dependencies |
|---|---|---|
| Virtual | Independent, unrelated work | None — parallel |
| Stacked | Sequential dependencies | Each builds on parent |
Stacked branches = virtual branches split into dependent sequence.
Default: Virtual branches are stacks of one.
| 类型 | 使用场景 | 依赖关系 |
|---|---|---|
| 虚拟分支 | 独立、不相关的工作 | 无 — 并行 |
| 堆叠分支 | 顺序依赖 | 每个分支基于父分支构建 |
堆叠分支 = 拆分为依赖序列的虚拟分支。
默认:虚拟分支是单个分支的栈。
Creating Stacks
创建栈
bash
undefinedbash
undefinedBase branch (no anchor)
基础分支(无锚点)
but branch new base-feature
but branch new base-feature
Stacked branch (--anchor specifies parent)
堆叠分支(--anchor 指定父分支)
but branch new child-feature --anchor base-feature
but branch new child-feature --anchor base-feature
Third level
第三层分支
but branch new grandchild-feature --anchor child-feature
**Result:** `base-feature` ← `child-feature` ← `grandchild-feature`
**Short form:** `-a` instead of `--anchor`
```bash
but branch new child -a parentbut branch new grandchild-feature --anchor child-feature
**结果:** `base-feature` ← `child-feature` ← `grandchild-feature`
**简写形式:** 使用 `-a` 代替 `--anchor`
```bash
but branch new child -a parentStack Patterns
栈模式
Common patterns: feature dependency chains, refactoring sequences, deep stacks.
Example - Feature Dependency:
bash
but branch new auth-core
but branch new auth-oauth --anchor auth-core
but branch new auth-social --anchor auth-oauthSee for detailed patterns with commit examples.
references/patterns.md常见模式:功能依赖链、重构序列、深层栈。
示例 - 功能依赖:
bash
but branch new auth-core
but branch new auth-oauth --anchor auth-core
but branch new auth-social --anchor auth-oauth查看 获取包含提交示例的详细模式。
references/patterns.mdPost-Hoc Stack Organization
事后栈组织
Convert independent branches into a stack by recreating with correct anchors:
- Create new branch with pointing to intended parent
--anchor - Move commits with
but rub <sha> <new-branch> - Delete original branch
See for detailed workflows.
references/reorganization.md通过使用正确的锚点重新创建分支,将独立分支转换为栈:
- 使用 指定目标父分支创建新分支
--anchor - 使用 移动提交
but rub <sha> <new-branch> - 删除原始分支
查看 获取详细工作流。
references/reorganization.mdPublishing Stacks
发布栈
Using CLI (Preferred)
使用CLI(推荐)
bash
undefinedbash
undefinedPush and create PR for a branch
推送分支并创建PR
but push dependent-feature
but pr new dependent-feature
but push dependent-feature
but pr new dependent-feature
Push all unpushed branches
推送所有未推送的分支
but push
`but push` + `but pr new` handles:
- Pushing branches to remote
- Creating PRs with correct base branches
- Updating existing PRs if already createdbut push
`but push` + `but pr new` 可处理:
- 将分支推送到远程仓库
- 创建带有正确基础分支的PR
- 若已创建PR则更新现有PRUsing GitHub CLI (Alternative)
使用GitHub CLI(替代方案)
bash
undefinedbash
undefinedPush branches
推送分支
git push -u origin base-feature
git push -u origin dependent-feature
git push -u origin base-feature
git push -u origin dependent-feature
Create PRs with correct base branches
创建带有正确基础分支的PR
gh pr create --base main --head base-feature
--title "feat: base feature"
--body "First in stack"
--title "feat: base feature"
--body "First in stack"
gh pr create --base base-feature --head dependent-feature
--title "feat: dependent feature"
--body "Depends on base-feature PR"
--title "feat: dependent feature"
--body "Depends on base-feature PR"
undefinedgh pr create --base main --head base-feature
--title "feat: base feature"
--body "First in stack"
--title "feat: base feature"
--body "First in stack"
gh pr create --base base-feature --head dependent-feature
--title "feat: dependent feature"
--body "Depends on base-feature PR"
--title "feat: dependent feature"
--body "Depends on base-feature PR"
undefinedGitHub Settings
GitHub设置
- Enable automatic branch deletion after merge
- Use Merge strategy (recommended) — no force pushes needed
- Merge bottom-to-top (sequential order)
- 启用合并后自动删除分支
- 使用合并策略(推荐)—— 无需强制推送
- 从下到上合并(顺序合并)
Conflict Handling in Stacks
栈中的冲突处理
GitButler resolves conflicts per-commit during rebase:
- When base branch updates, dependent commits rebase automatically
- Conflicted commits marked but don't block other commits
- Resolve conflicts per affected commit
- Partial resolution can be saved and continued later
bash
undefinedGitButler在变基期间按提交解决冲突:
- 当基础分支更新时,依赖提交会自动变基
- 冲突提交会被标记,但不会阻塞其他提交
- 针对受影响的提交解决冲突
- 部分解决结果可保存并稍后继续
bash
undefinedUpdate base (may trigger rebases in stack)
更新基础分支(可能触发栈中的变基)
but pull
but pull
Check which commits have conflicts
检查哪些提交存在冲突
but status
but status
Resolve in editor, GitButler auto-detects resolution
在编辑器中解决冲突,GitButler会自动检测解决结果
**Unlike git rebase:** Remaining commits continue rebasing even if some conflict.
**与git rebase不同:** 即使部分提交存在冲突,剩余提交仍会继续变基。Stack Reorganization
栈重组
Key operations for restructuring stacks:
| Operation | Command |
|---|---|
| Squash commits | |
| Move commit | |
| Split branch | Create anchored branch, move commits |
See for detailed examples.
references/reorganization.md重组栈的关键操作:
| 操作 | 命令 |
|---|---|
| 合并提交 | |
| 移动提交 | |
| 拆分分支 | 创建带锚点的分支,移动提交 |
查看 获取详细示例。
references/reorganization.mdStack Navigation
栈导航
Note: Virtual branches don't need checkout — all branches active simultaneously.
bash
undefined注意: 虚拟分支无需切换——所有分支同时处于活跃状态。
bash
undefinedView full stack structure
查看完整栈结构
but status
but status
Work on any branch directly (no checkout needed)
直接在任意分支上工作(无需切换)
but commit base-feature -m "update base"
but commit dependent-feature -m "update dependent"
but commit base-feature -m "update base"
but commit dependent-feature -m "update dependent"
Inspect a specific branch
检查特定分支
but show dependent-feature
but show dependent-feature
JSON for programmatic analysis
用于程序化分析的JSON格式
but show dependent-feature --json | jq '.commits[] | .id'
<rules>
ALWAYS:
- Create stacks with `--anchor` from the start
- Merge stacks bottom-to-top (base first, dependents after)
- Snapshot before reorganizing: `but oplog snapshot --message "Before stack reorganization"`
- Keep each level small (100-250 LOC) for reviewability
- Delete empty branches after reorganization
NEVER:
- Skip stack levels when merging
- Stack independent, unrelated features (use virtual branches)
- Create deep stacks (5+ levels) without good reason
- Forget anchor when creating dependent branches
</rules>but show dependent-feature --json | jq '.commits[] | .id'
<rules>
必须遵守:
- 从一开始就使用 `--anchor` 创建栈
- 从下到上合并栈(先合并基础分支,再合并依赖分支)
- 重组前创建快照:`but oplog snapshot --message "Before stack reorganization"`
- 保持每个层级的代码量较小(100-250行代码)以便评审
- 重组后删除空分支
禁止:
- 合并时跳过栈层级
- 堆叠独立、不相关的功能(使用虚拟分支)
- 无正当理由创建深层栈(5层以上)
- 创建依赖分支时忘记指定锚点
</rules>Troubleshooting
故障排除
| Symptom | Cause | Solution |
|---|---|---|
Stack not showing in | Missing | Recreate with correct anchor |
| Commits in wrong stack level | Wrong branch targeted | |
| Can't merge middle of stack | Wrong order | Merge bottom-to-top only |
| 症状 | 原因 | 解决方案 |
|---|---|---|
| 缺少 | 使用正确的锚点重新创建分支 |
| 提交位于错误的栈层级 | 目标分支错误 | |
| 无法合并栈中间的分支 | 合并顺序错误 | 仅从下到上合并 |
Recovery
恢复
To fix a branch with wrong/missing anchor: create new branch with correct anchor, move commits with , delete original.
but rubSee for complete recovery procedures.
references/reorganization.md要修复锚点错误/缺失的分支:创建带有正确锚点的新分支,使用 移动提交,删除原始分支。
but rub查看 获取完整恢复流程。
references/reorganization.mdBest Practices
最佳实践
Planning
规划
- Start simple: 2-3 levels max initially
- Single responsibility per level
- Only stack when there's a real dependency
- 从简单开始:最初最多2-3层
- 每个层级单一职责
- 仅当存在真实依赖时才使用堆叠
Maintenance
维护
- Run regularly to verify structure
but status - Commit to correct branches immediately
- Clean up empty branches
- 定期运行 验证结构
but status - 立即提交到正确的分支
- 清理空分支
Communication
沟通
- Clear commit messages explaining why stack level exists
- Descriptive names indicating stack relationship
- Share when coordinating
but status
- 清晰的提交消息,解释栈层级存在的原因
- 描述性的分支名称,表明栈关系
- 协作时分享 结果
but status
Reference Files
参考文件
- — Detailed stack patterns (feature dependency, refactoring, deep stacks)
references/patterns.md - — Post-hoc organization, squashing, moving commits, splitting
references/reorganization.md
- — 详细的栈模式(功能依赖、重构、深层栈)
references/patterns.md - — 事后组织、合并提交、移动提交、拆分分支
references/reorganization.md
Related Skills
相关技能
- gitbutler-virtual-branches — Core GitButler workflows
- gitbutler-complete-branch — Merging to main
- gitbutler-multi-agent — Multi-agent coordination
- gitbutler-virtual-branches — GitButler核心工作流
- gitbutler-complete-branch — 合并到主分支
- gitbutler-multi-agent — 多Agent协作
External
外部资源
</references>
</references>