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

# graph

> Visualize the branch stack tree

`gx graph` displays a tree visualization of all branches and their parent-child relationships, with status indicators for the current branch, merged branches, and orphaned branches.

## Usage

```bash theme={null}
gx graph
```

## Example Output

```
Branch Stack:

|-- main
|   |-- feature/auth  (+3/-0)
|   |   `-- feature/tests  * HEAD  (+2/-0)
|   `-- fix/login  + merged
`-- develop
    `-- feature/dashboard  (+5/-2)

Orphaned Branches:
`-- old-experiment  ! orphaned

Legend: * current branch  + merged  (+ahead/-behind)  ! orphaned
Relationships stored in .git/gx/stack.json
```

## Indicators

| Indicator    | Meaning                                      |
| ------------ | -------------------------------------------- |
| `* HEAD`     | The currently checked-out branch             |
| `+ merged`   | Branch is fully merged into its parent       |
| `(+N/-M)`    | N commits ahead, M commits behind the parent |
| `! orphaned` | Branch whose parent no longer exists         |

## Tree Structure

* **Roots** are branches that are not children of any other branch (typically main/master)
* **Children** are indented under their parent with tree-drawing characters (`\|--` and `` `-- ``)
* The main branch is always listed first among roots
* Children within each parent are sorted alphabetically
* Only branches explicitly created with `gx stack` appear in the graph. There is no auto-discovery of relationships

## Orphaned Branches

Branches whose recorded parent no longer exists are shown in a separate "Orphaned Branches" section with a warning indicator. These can be cleaned up with `gx nuke --orphans`.

<Tip>
  Run `gx graph` after creating branches to verify the stack looks correct. Only branches registered with `gx stack` will appear.
</Tip>

<Accordion title="Details">
  * The tree is built from `.git/gx/stack.json` using only explicitly stacked branches
  * `BuildTree` is read-only and never writes to `stack.json`
  * Ahead/behind counts are computed for each branch relative to its configured parent
  * Merged status is checked with `git branch --merged <parent>`
</Accordion>
