> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cubic.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a stack

> Build multiple pull requests on top of each other with mg.

## Interactive Demo

Learn about stacked PRs interactively in your CLI:

```
mg demo
```

Stacks allow you to break a big feature into multiple dependent branches, each with its own PR. This approach makes it easier to review smaller, self-contained changes instead of dealing with one massive pull request.

<Note>
  **Prerequisites**

  * A repo already [initialized with `mg init`](/how-to-guides/initialize-in-repo).
  * Basic familiarity with key mg commands like `mg branch` and `mg push`.
</Note>

***

## 1. Start from your trunk

Begin by checking out your trunk branch (often `main` or `master`):

```bash theme={null}
mg checkout main
```

***

## 2. First branch

Make your first set of changes:

```bash theme={null}
mg branch part_a
echo "console.log('Part A')" > partA.js
mg add partA.js
mg commit -m "feat: part A"
```

You can open a pull request immediately by pushing:

```bash theme={null}
mg push
```

<Tip>When you push, `mg` will prompt you to update the PR title and description if needed.</Tip>

***

## 3. Second branch on top

Let's build on that first branch:

```bash theme={null}
mg branch part_b
echo "console.log('Part B')" > partB.js
mg add partB.js
mg commit -m "feat: part B"
```

Now, if you run:

```bash theme={null}
mg list
```

You'll see a short tree:

```
main
 └─ feat_part_A
    └─ feat_part_B
```

Each of these branches can become its own PR.

***

## 4. Push & review your branches

```bash theme={null}
mg push --all
```

This command updates (or creates) your pull requests on cubic (and GitHub). Each branch is a smaller PR, but together, they form one cohesive feature. Your team can review them in sequence or parallel, merging them once approved.

<Tip>
  If you prefer pushing branches one at a time, that's fine, too. Just call `mg push` while on each
  branch.
</Tip>

***

## 5. Keep moving

* **Check out the next branch in the stack**: `mg next`

* **Check out the previous branch in the stack**: `mg prev`

* **Visualize again**: `mg list`

Add as many branches as you need for each logical slice of your feature.

***

### Best Practices

* **One logical change per branch**: Keep each branch focused on a single feature or sub-feature.

* **Name branches descriptively**: It's easier to see what each PR does when reading the branch list.

* **Push frequently**: Ensures your teammates can see your ongoing work and provide feedback early.

***

### Next steps

* [Keep your stack updated](/how-to-guides/keep-your-stack-updated): Sync from `main` if teammates add new commits.

* [Merge your stack in cubic](/how-to-guides/merge-your-stack): Once each PR is ready, merge them in the right order via the cubic UI.

<Check>
  That's it! You've built a multi-branch, multi-PR stack that's simpler for your team to review and
  merge. Happy stacking!
</Check>
