The Problem
Without stacking, you either:- Wait: Finish PR 1, wait for review and merge, then start PR 2. Slow.
- Branch from main: Start PR 2 from main, duplicate or conflict with PR 1’s changes. Messy.
- Stack manually: Create PR 2 on top of PR 1’s branch, but then juggle rebasing when PR 1 changes. Error-prone.
How gx Solves It
gx tracks parent-child relationships between branches and automates the rebasing, pushing, and bookkeeping:feature/auth changes (new commits, or after code review updates), gx sync --stack rebases the entire chain in order and pushes all branches.
Workflow
1. Create the stack
2. Visualize
3. Sync after changes
When you update a branch (e.g., address PR review feedback onfeature/auth):
feature/tests and feature/dashboard in sequence, then pushes all three.
4. Navigate
Move through the stack without remembering branch names:5. Retarget after merge
Whenfeature/auth is merged into main, retarget feature/tests:
feature/tests onto main, pushes, updates the config, and retargets the GitHub PR.
6. Clean up
The stack.json Format
gx stores stack relationships in.git/gx/stack.json:
Fields
| Field | Description |
|---|---|
branches.<name>.parent | The parent branch name |
branches.<name>.parent_head | The parent’s HEAD SHA when the relationship was last synced |
branches.<name>.pr_number | PR number (optional, for future use) |
metadata.main_branch | The trunk branch name |
metadata.last_updated | Timestamp of last config update |
Key Properties
- Stored in
.git/gx/: Not tracked by git, local to each clone - Auto-created: First
gx stackcall creates it if missing - Self-healing:
gx graphdetects and repairs missing relationships - Legacy migration: Old
{"relationships": {"child": "parent"}}format is auto-migrated
Related Commands
| Command | Purpose |
|---|---|
gx init | Initialize stacking config |
gx stack | Create a stacked branch |
gx sync | Rebase and push the stack |
gx retarget | Move a branch to a new parent |
gx graph | Visualize the stack tree |
gx up/down/top/bottom | Navigate the stack |
gx parent | Print parent branch (for scripting) |
gx view | Stack overview with PR status |
gx handoff | Generate branch summary |