Skip to content

Add git stack pop - #53

Merged
DomBlack merged 3 commits into
mainfrom
pop
Oct 16, 2026
Merged

DomBlack merged 3 commits into
mainfrom
pop

Conversation

@DomBlack

@DomBlack DomBlack commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Taking a branch out of the middle of a stack was the last thing the README still sent you to gh stack modify for. It comes up when a branch shouldn't be its own PR yet, or you want to redo it differently: today that's a manual reset, deleting the branch, fixing the metadata, restacking what was above it and closing the PR on GitHub.

git stack pop (and git pop) does it for the current branch, wherever it is in the stack. You end up on its parent with the branch's changes staged, as git reset --soft would leave them. The branch is deleted, and the branches above are restacked onto the parent so they no longer carry the popped commits. It refuses on a dirty working tree (your changes would mix with the popped ones), or when the branch isn't on its parent yet. Agents get stack_pop.

It's a reshape like reorder, move and fold. The restack of the branches above runs first, while the popped branch is still checked out and untouched. Only once that's done does HEAD move to the parent and the branch go. So a conflict stops like any restack: git stack continue finishes the pop, and git stack abort puts everything back, the popped branch included. Its PR goes on the same queue as fold's, closed at the next submit.

One thing for later: after a pop then an abort, the branch's entry comes back without gh stack's PR link. gh stack picks it up again at the next submit.

Pop needs to leave a branch's changes staged on its parent, which is what you get when HEAD moves to the parent but the index and working tree stay as they are. A switch or reset would rewrite one or the other.

So the git client gets PointHEAD, a git symbolic-ref onto the branch. git will point HEAD at a branch that doesn't exist without complaint, so it checks the branch is there first.
Taking a branch back out of a stack (to redo it, or because it shouldn't be its own PR yet) still meant going to gh stack modify. Pop does it here: the current branch goes away and its changes end up staged on its parent, much like git reset --soft onto the parent would leave them.

It's a reshape like reorder and move. The branch is dropped from its stack and the branches above are restacked onto the parent, so they no longer carry its commits. Only once that's done does HEAD move to the parent (without touching the index or working tree) and the branch get deleted. That order means the restack never has to deal with the checked out branch, and if it stops on a conflict the saved state remembers the finish so git stack continue does it at the end; git stack abort puts the branch back in its stack, since nothing was deleted yet.

It refuses up front when the tree has changes to tracked files (they'd be mixed in with the popped ones and you couldn't tell them apart), when the branch isn't sitting on its parent, and when the parent is checked out in another worktree. The branch's open PR is queued to close at the next submit and the stack queued for dissolving, like the other reshapes.
This puts the pop use case behind a command, so taking a branch back out of a stack no longer needs gh stack modify. git stack pop (or git pop) works on the branch you're on, says which parent its changes are now staged on, what it restacked, and which PR the next submit will close.

A pop that stops on a conflict is finished by git stack continue like any other reshape, and continue now says when it also finished a pop, since that's the moment HEAD moves and the branch goes away.

Agents get the same thing as stack_pop, and the README, MCP docs, skill and architecture notes cover it. The README's list of things that still need gh stack is down to folding a branch into another.
Copilot AI balanced review requested due to automatic review settings October 16, 2026 12:47
@DomBlack DomBlack changed the title pop Add git stack pop Oct 16, 2026
@DomBlack DomBlack added the enhancement New feature or request label Oct 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@DomBlack
DomBlack merged commit 29677aa into main Oct 16, 2026
5 of 6 checks passed
@DomBlack
DomBlack deleted the pop branch October 16, 2026 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants