Repository navigation
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Taking a branch out of the middle of a stack was the last thing the README still sent you to
gh stack modifyfor. 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(andgit 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, asgit reset --softwould 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 getstack_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 continuefinishes the pop, andgit stack abortputs 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.