Use when the user wants to change a branch's position in the stack, remove it from the stack, or runs /gs-move.
You are implementing /gs-move. This reorders a branch within the stack, or detaches it entirely. No pushing, no PRs.
Note: Examples below use main as the root branch. In practice, use <root-branch> (read from git config git-stack.root) wherever main appears in commands.
git status --porcelain
If the output shows any changes (staged, unstaged, or untracked) or merge conflicts, stop and tell the user to commit, stash, or resolve conflicts before reordering the stack.
Follow the stack discovery pattern (git config only, no fallback). Build the ordered branch list from root to tip.
Get the current branch:
git rev-parse --abbrev-ref HEAD
Display the full stack with the current branch marked. Example:
Stack:
<root-branch>
└─ stack/01-feature-a
└─ stack/02-feature-b ← (you are here)
└─ stack/03-feature-c
Present the following options:
What would you like to do?
- Move up — swap with the parent branch (move closer to
<root-branch>)- Move down — swap with the child branch (move further from
<root-branch>)- Move to position — pick a specific position in the stack
- Detach — remove from stack and make it a standalone branch off
<root-branch>
Wait for the user to choose. Then proceed to the matching section below.
Swap the current branch with the one immediately above it.
Precondition: the current branch must not already be the closest to <root-branch> (i.e. its parent cannot be <root-branch>). If it is, report:
Already the first branch in the stack (closest to
<root-branch>). Nothing to move.
Example:
Stack before: main → A → B → C. Current branch is B.
After "move up": main → B → A → C
Metadata updates:
git config git-stack.B.parent <root-branch>
git config git-stack.A.parent B
git config git-stack.C.parent A
Rebase order (use --onto to transplant each branch from its old parent to its new parent):
git rebase --onto B <root-branch> A (transplant A from <root-branch> to B)git rebase --onto A B C (transplant C from B to A)Return to B when done.
General algorithm:
Let current = current branch, above = its parent, above-parent = parent of above, below = child of current (may be null).
git-stack.current.parent = above-parentgit-stack.above.parent = currentbelow exists: set git-stack.below.parent = abovegit rebase --onto current above-parent above (transplant above from above-parent to current)below exists: git rebase --onto above current below (transplant below from current to above)git rebase --onto <new-parent> <old-parent> <branch>, in order.current.Swap the current branch with the one immediately below it.
Precondition: the current branch must not already be at the tip of the stack (farthest from <root-branch>, with no child branch). If it is, report:
Already the last branch in the stack (farthest from
<root-branch>). Nothing to move.
Example:
Stack before: main → A → B → C. Current branch is B.
After "move down": main → A → C → B
Metadata updates:
git config git-stack.C.parent A
git config git-stack.B.parent C
Rebase order (use --onto to transplant each branch from its old parent to its new parent):
git rebase --onto A B C (transplant C from B to A)git rebase --onto C A B (transplant B from A to C)Return to B when done.
General algorithm:
Let current = current branch, parent = parent of current, below = child of current, below-child = child of below (may be null).
git-stack.below.parent = parentgit-stack.current.parent = belowbelow-child exists: set git-stack.below-child.parent = currentgit rebase --onto parent current below (transplant below from current to parent)git rebase --onto below parent current (transplant current from parent to below)below-child exists: git rebase --onto current below below-child (transplant below-child from below to current)git rebase --onto <new-parent> <old-parent> <branch>, in order.current.Show the stack with numbered insertion positions (like /gs-insert). Example:
Stack:
<root-branch>
↓ ← [1] move here
stack/01-feature-a
↓ ← [2] move here
stack/02-feature-b ← (you are here)
↓ ← [3] move here
stack/03-feature-c
Where should this branch be moved? Enter a number from the list above.
Wait for the user to choose a number. Skip the position that corresponds to the branch's current location (moving there is a no-op — report "Already in that position" and stop).
Once the target position is chosen, update metadata and rebase as needed:
current from its current position: update the branch that was below current to point to current's old parent.current at the target position: update current's parent to <branch-above-target>, and update <branch-below-target>.parent to current (if a branch exists below).git rebase --onto <new-parent> <old-parent> <branch> for each. Affected branches are any branches whose parent changed or that sit downstream of a changed parent.current.Remove the current branch from the stack entirely and make it a standalone branch off <root-branch>.
Example:
Stack before: main → A → B → C. User detaches B.
Result: stack is main → A → C, B is standalone off <root-branch>.
Metadata updates:
git config git-stack.C.parent A
git config --unset git-stack.B.parent
Rebase order (use --onto to transplant each branch from its old parent to its new parent):
git rebase --onto <root-branch> A B (transplant B from A to <root-branch>)git rebase --onto A B C (transplant C from B to A, closing the gap)Return to B when done.
General algorithm:
Let current = current branch, parent = parent of current, below = child of current (may be null).
below exists: set git-stack.below.parent = parentgit-stack.current.parent:
git config --unset git-stack.current.parent
git rebase --onto <root-branch> parent current (transplant current from parent to <root-branch>).below exists: git rebase --onto parent current below (transplant below from current to parent), then continue rebasing any further downstream branches with git rebase --onto <new-parent> <old-parent> <branch>, in order.current.After any move action, run the project's verification commands as defined in CLAUDE.md (e.g., pnpm typecheck, pnpm lint) on each affected branch (branches that were rebased or had metadata changed).
Report any failures. Do not declare the move complete until the user has acknowledged any failures.
Follow the conflict handling pattern. Pause on genuine conflicts — list conflicted files, show the user, wait for resolution.
Co-Authored-By lines.🤖 Generated with Claude Code lines.gh is not required — this is entirely local.<root-branch> (parent = <root-branch>): "Move up" is a no-op. Report and stop.<root-branch> (no child): "Move down" is a no-op. Report and stop.<root-branch>. The stack becomes empty.git status shows uncommitted changes or unresolved conflicts before starting, stop and tell the user to clean up first.