Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,22 @@ gw switch # interactive picker
gw switch <branch-name> # direct checkout
```

### Splitting a fat branch into a stack
```bash
gw split # interactive TUI to assign commits to buckets
gw split --plan plan.txt # non-interactive, reads from plan file
gw split --continue # resume after resolving cherry-pick conflicts
gw split --abort # roll back, delete created branches
```

### Adopting existing branches
```bash
gw adopt branch-a branch-b branch-c --base main
```

## Conflict Resolution

If `gw rebase` or `gw sync` hits a conflict:
If `gw rebase`, `gw sync`, or `gw split` hits a conflict:
```bash
# resolve conflicts in your editor
git add <resolved files>
Expand All @@ -62,7 +70,7 @@ gw rebase --continue # resumes the cascade
gw rebase --abort # rolls back ALL branches to pre-rebase state
```

Most commands are blocked during a propagation. Only `gw tree` and `gw switch` work.
Most commands are blocked during a propagation or split. Only `gw tree`, `gw switch`, `gw status`, and `gw diff` work.

## Important Notes

Expand All @@ -82,7 +90,7 @@ cargo install --path . # install to ~/.cargo/bin/gw
## Architecture

- `src/cli.rs` - clap derive CLI definitions
- `src/commands/` - one file per command (stack, branch, adopt, rebase, sync, push, switch, tree, config, completions)
- `src/commands/` - one file per command (stack, branch, adopt, rebase, sync, push, switch, split, tree, config, completions)
- `src/git.rs` - git CLI wrapper (all git operations go through here)
- `src/propagation.rs` - shared rebase cascade engine
- `src/state.rs` - TOML serialization for stack configs and propagation state
Expand Down
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Everything lives in `.git/gw/` and never gets pushed to the remote.
- [Why this exists](#why-this-exists)
- [Install](#install)
- [Quick start](#quick-start)
- [Already have a fat branch? Split it](#already-have-a-fat-branch-split-it)
- [Already have branches? Adopt them](#already-have-branches-adopt-them)
- [Configuration](#configuration)
- [Commands](#commands)
Expand Down Expand Up @@ -129,6 +130,32 @@ gw sync --rebase
gw switch
```

## Already have a fat branch? Split it

If you've got a single branch with a bunch of commits that should really be separate PRs, `gw split` decomposes it into a clean stack:

```bash
gw split
```

An interactive TUI lets you assign each commit to a named bucket. When you confirm, gw cherry-picks the commits into new branches forming a linear stack. The original branch is kept as a backup.

You can also use a plan file for scripting:

```bash
gw split --plan split-plan.txt --base main
```

Plan file format:
```
pick <full-sha> auth
pick <full-sha> auth
pick <full-sha> dashboard
pick <full-sha> dashboard
```

If a cherry-pick hits a conflict, resolve it and run `gw split --continue`. To undo everything: `gw split --abort`.

## Already have branches? Adopt them

If you've already got a chain of branches you've been managing by hand, you don't need to recreate anything. Just tell gw about them:
Expand Down Expand Up @@ -169,6 +196,10 @@ gw config set-delete-on-merge true
| `gw branch create <name>` | Add a branch to the current stack |
| `gw branch remove <name>` | Remove a branch and re-parent children |
| `gw adopt <branches...>` | Adopt existing branches into a stack |
| `gw split` | Interactively split a branch into a stack |
| `gw split --plan <file>` | Split using a plan file |
| `gw split --continue` | Resume after resolving cherry-pick conflicts |
| `gw split --abort` | Roll back split and delete created branches |
| `gw rebase` | Propagate rebases to descendants |
| `gw rebase --continue` | Resume after resolving conflicts |
| `gw rebase --abort` | Roll back all branches |
Expand Down
8 changes: 8 additions & 0 deletions plugins/gw/skills/gw/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,20 @@ You are working in a repo that uses **gw**, a stacked branch manager. Use gw too

When the user has a large change or asks to split work into reviewable pieces:

**If the work hasn't been done yet:**
1. Create a stack with `gw_stack_create`
2. Make commits for the first logical unit (e.g., data model changes)
3. Create the next branch with `gw_branch_create` for the next unit (e.g., API layer)
4. Repeat until done
5. Each branch becomes its own PR, stacked on the previous one

**If the work is already on a single branch:**
1. Use `gw split` to decompose the existing branch into a clean stack
2. The interactive TUI lets you assign each commit to a named bucket/branch
3. Or use `gw split --plan <file>` with a plan file for scripting
4. Cherry-pick conflicts can be resolved with `gw split --continue`
5. Use `gw split --abort` to roll back if needed

Good stack boundaries: model/schema changes, API/service layer, UI/frontend, tests, migrations. Each branch should be independently reviewable and tell a coherent story.

### Pushing work
Expand Down
26 changes: 26 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ pub enum Commands {
/// Show log of all stacks with branches and commits
#[command(alias = "tree")]
Log(TreeArgs),
/// Split a branch into a stack of focused branches
Split(SplitArgs),
/// Configure gw settings
Config(ConfigArgs),
/// Generate shell completions
Expand Down Expand Up @@ -177,6 +179,30 @@ pub struct DiffArgs {
pub no_difftastic: bool,
}

// -- Split --

#[derive(Args)]
pub struct SplitArgs {
/// Plan file mapping commits to branches (non-interactive mode)
#[arg(long)]
pub plan: Option<String>,
/// Base branch to split from (defaults to merge-base detection)
#[arg(long)]
pub base: Option<String>,
/// Stack name for the new stack (defaults to original branch name)
#[arg(long)]
pub name: Option<String>,
/// Skip confirmation prompt
#[arg(long)]
pub yes: bool,
/// Continue after resolving cherry-pick conflicts
#[arg(long = "continue", id = "split_continue", conflicts_with = "split_abort")]
pub cont: bool,
/// Abort the split and clean up created branches
#[arg(long = "abort", id = "split_abort", conflicts_with = "split_continue")]
pub abort: bool,
}

// -- Config --

#[derive(Args)]
Expand Down
2 changes: 2 additions & 0 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub mod mcp_server;
pub mod mcp_setup;
pub mod push;
pub mod rebase;
pub mod split;
pub mod split_tui;
pub mod stack;
pub mod status;
pub mod switch;
Expand Down
Loading