Skip to content

Add git stack create --insert - #54

Merged
DomBlack merged 2 commits into
mainfrom
create-insert
Oct 16, 2026
Merged

DomBlack merged 2 commits into
mainfrom
create-insert

Conversation

@DomBlack

@DomBlack DomBlack commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

gh stack can only add a branch at the top of a stack, so git create on a branch in the middle refused with not_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 as insert on stack_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 abort puts 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.

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.
Copilot AI balanced review requested due to automatic review settings October 16, 2026 12:57
@DomBlack DomBlack changed the title create insert Add git stack create --insert 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 9d011a4 into main Oct 16, 2026
5 of 6 checks passed
@DomBlack
DomBlack deleted the create-insert branch October 16, 2026 13:04
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