|
| 1 | +# gh-stack |
| 2 | + |
| 3 | +A GitHub CLI extension for managing stacked pull requests. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Local-first** — Stack metadata lives in `.git/config`, not a remote service |
| 8 | +- **GitHub-native** — Works with the `gh` CLI you already use |
| 9 | +- **Conflict-aware** — Cascade rebases with continue/abort recovery |
| 10 | +- **Automatic sync** — Detects merged PRs, retargets orphaned branches, cascades all |
| 11 | + |
| 12 | +## Quick Start |
| 13 | + |
| 14 | +### Prerequisites |
| 15 | + |
| 16 | +- Go 1.22+ |
| 17 | +- [GitHub CLI](https://cli.github.com/) (`gh`) installed and authenticated |
| 18 | + |
| 19 | +### Installation |
| 20 | + |
| 21 | +```bash |
| 22 | +# Build from source |
| 23 | +git clone https://github.com/boneskull/gh-stack.git |
| 24 | +cd gh-stack |
| 25 | +make build |
| 26 | + |
| 27 | +# Install as gh extension |
| 28 | +make gh-install |
| 29 | +``` |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +### Initialize a Repository |
| 34 | + |
| 35 | +```bash |
| 36 | +gh stack init |
| 37 | +``` |
| 38 | + |
| 39 | +This sets your current branch (typically `main`) as the trunk. |
| 40 | + |
| 41 | +### Create a Stacked Branch |
| 42 | + |
| 43 | +```bash |
| 44 | +gh stack create feature-auth |
| 45 | +``` |
| 46 | + |
| 47 | +Creates `feature-auth` branched from your current position and tracks it as a child. |
| 48 | + |
| 49 | +### View Your Stack |
| 50 | + |
| 51 | +```bash |
| 52 | +gh stack log |
| 53 | +``` |
| 54 | + |
| 55 | +```text |
| 56 | +main |
| 57 | +└── feature-auth |
| 58 | + └── feature-auth-tests |
| 59 | +``` |
| 60 | + |
| 61 | +### Create PRs for Your Stack |
| 62 | + |
| 63 | +```bash |
| 64 | +gh stack pr |
| 65 | +``` |
| 66 | + |
| 67 | +Creates a PR targeting the parent branch. If a PR already exists, updates its base. |
| 68 | + |
| 69 | +### Push Your Stack |
| 70 | + |
| 71 | +```bash |
| 72 | +gh stack push |
| 73 | +``` |
| 74 | + |
| 75 | +Force-pushes (with lease) all branches from trunk to your current branch, updating PR bases as needed. |
| 76 | + |
| 77 | +### Rebase After Parent Changes |
| 78 | + |
| 79 | +```bash |
| 80 | +gh stack cascade |
| 81 | +``` |
| 82 | + |
| 83 | +Rebases the current branch onto its parent, then cascades to all descendants. If conflicts occur: |
| 84 | + |
| 85 | +```bash |
| 86 | +# Resolve conflicts, then: |
| 87 | +gh stack continue |
| 88 | + |
| 89 | +# Or abort: |
| 90 | +gh stack abort |
| 91 | +``` |
| 92 | + |
| 93 | +### Sync Everything |
| 94 | + |
| 95 | +```bash |
| 96 | +gh stack sync |
| 97 | +``` |
| 98 | + |
| 99 | +Fetches from origin, fast-forwards trunk, detects merged PRs, cleans up merged branches, retargets orphaned children to trunk, and cascades all branches. |
| 100 | + |
| 101 | +## Commands |
| 102 | + |
| 103 | +| Command | Description | |
| 104 | +| ---------- | ----------------------------------------------------- | |
| 105 | +| `init` | Initialize stack tracking with trunk branch | |
| 106 | +| `log` | Display branch tree | |
| 107 | +| `create` | Create new branch stacked on current | |
| 108 | +| `adopt` | Start tracking an existing branch | |
| 109 | +| `orphan` | Stop tracking a branch | |
| 110 | +| `link` | Associate PR number with branch | |
| 111 | +| `unlink` | Remove PR association | |
| 112 | +| `pr` | Create or update PR targeting parent | |
| 113 | +| `push` | Force-push stack with `--force-with-lease` | |
| 114 | +| `cascade` | Rebase branch and descendants onto parents | |
| 115 | +| `continue` | Resume cascade after conflict resolution | |
| 116 | +| `abort` | Cancel cascade operation | |
| 117 | +| `sync` | Full sync: fetch, cleanup merged PRs, cascade all | |
| 118 | + |
| 119 | +## How It Works |
| 120 | + |
| 121 | +gh-stack stores metadata in your local `.git/config`: |
| 122 | + |
| 123 | +```ini |
| 124 | +[stack] |
| 125 | + trunk = main |
| 126 | + |
| 127 | +[branch "feature-auth"] |
| 128 | + stackParent = main |
| 129 | + stackPR = 123 |
| 130 | + |
| 131 | +[branch "feature-auth-tests"] |
| 132 | + stackParent = feature-auth |
| 133 | + stackPR = 124 |
| 134 | +``` |
| 135 | + |
| 136 | +No remote service required. Your stack relationships stay with your repository. |
| 137 | + |
| 138 | +## Acknowledgements |
| 139 | + |
| 140 | +Inspired by [Graphite](https://graphite.dev/). |
| 141 | + |
| 142 | +## License |
| 143 | + |
| 144 | +Copyright © 2026 [Christopher "boneskull" Hiller](https://github.com/boneskull). Licensed under [Apache-2.0](LICENSE). |
0 commit comments