gx stack creates a new branch based on a parent branch and records the relationship in the stack config. This is the foundation for stacked PR workflows.
Usage
Arguments
| Argument | Description |
|---|---|
new-branch | Name of the branch to create |
parent-branch | Branch to create it on top of |
Example
What Happens
- Creates the new branch at the tip of the parent branch (
git checkout -b <new> <parent>) - Records the parent-child relationship in
.git/gx/stack.json - Stores the parent’s current HEAD SHA as
parent_head(used bygx syncandgx retargetto know the exact base point) - Switches you to the new branch
Parent Head Tracking
When gx creates a stacked branch, it records the parent’s HEAD SHA at that moment. Thisparent_head value is critical for accurate rebasing:
gx syncuses it to know exactly which commits belong to each branch in the chaingx retargetuses it as the--ontobase when moving a branch to a new parent- It is updated automatically after each successful sync
If you have uncommitted changes when running
gx stack, gx prints a warning: WARN You have uncommitted changes. They will carry over to the new branch. The branch is still created — your changes come along.Edge cases
Edge cases
- If the new branch already exists, gx prints
ERROR Branch '<name>' already exists. - If the parent branch does not exist, gx prints
ERROR Parent branch '<name>' does not exist. - If fewer than 2 arguments are provided, gx prints
ERROR Usage: gx stack <new-branch> <parent-branch> - The stack config is auto-created if it does not exist yet (equivalent to running
gx initfirst)