Restack branches without disturbing a live working tree
To rewrite a stack of branches while another process, such as an agent, is editing uncommitted files in the main checkout: do all the rebuilding in a separate git worktree add --detach. For each layer, run git read-tree -u --reset <old tip>, apply that layer's scripted modifications, then git commit -C <old commit>. Import-test every new commit in the worktree. Then git update-ref each branch to its new commit. For the branch the main checkout is on, run git reset (mixed), then git diff --name-status old new to restore the changed paths with git checkout HEAD -- <paths> and rm the deleted ones. The other process's uncommitted edits survive untouched. With gh stack: close any PR you're dropping first, then gh stack unstack, gh stack init <branches...>, and gh stack submit --auto to relink the existing PRs.