Repository navigation
Add git stack create --insert - #54
Merged
Merged
Conversation
gh stack can only add a branch at the top of a stack, so create refused anywhere else and the workaround was to create on top and reorder it down, which restacks the new branch through every branch in between for no reason. With Insert, create makes the branch from HEAD itself and puts it in the stack right above the current branch through the same reshape a reorder uses, so the branch that was above gets its base fixed and the stack's GitHub id is cleared and queued to be dissolved at the next submit. Then it commits exactly like a normal create, and a failed commit puts the stack back the way it was before undoing the branch as usual. Only after that are the branches above restacked onto the new commit. That restack runs like the one after a modify rather than as part of the reshape, so after a conflict abort puts the branches above back and leaves the new branch in the stack with its commit (i.e. you're left with a stack that needs a restack, not with a commit on a branch that isn't tracked). Insert on the top branch is a plain create, and on a trunk it's refused.
Starting a branch in the middle of a stack was one of the things the README still said git-stack couldn't do; you had to go to the top, create it there and reorder it into place. So git stack create --insert (or -i) now creates the branch right above the one you're on and restacks the ones above onto it. It prints where the branch went and how many branches were restacked, and on a conflict it still says the branch was created before the usual continue / abort steps. The not_at_top error mentions it as a way out. Agents get it as insert on stack_create, which is now marked destructive since it can rebase other branches, and a conflict there keeps the result alongside the error like stack_reorder does. The README, the MCP docs and server instructions, the agent skill and the architecture notes cover it, including why abort keeps the new branch.
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.
gh stack can only add a branch at the top of a stack, so
git createon a branch in the middle refused withnot_at_top, and the only way to get a branch in there was to create it on top and reorder it into place.git stack create --insert(-i) now puts the new branch right above the current one and restacks the branches that were above onto it. Everything else about create is the same: staging flags, message,--ai, and undoing the branch when the commit fails. On the top branch it's just a plain create. Agents get it asinsertonstack_create, which is now marked destructive since it can rebase other branches.Under the hood it's a reshape without a restack that puts the branch in the list and queues the GitHub stack to be regrouped at the next submit, like a reorder does. Then comes the commit, then a restack of the branches above, the way modify does it. So on a conflict,
git stack abortputs the branches above back but keeps the new branch and its commit in the stack (you stay on it, and the stack shows it needs a restack). Putting the order back instead would have left the new branch untracked, holding a commit with nowhere to go.