Skip to content

Add git stack rename - #57

Merged
DomBlack merged 2 commits into
untrackfrom
rename
Oct 16, 2026
Merged

DomBlack merged 2 commits into
untrackfrom
rename

Conversation

@DomBlack

@DomBlack DomBlack commented Oct 16, 2026 •

Copy link
Copy Markdown
Owner

Renaming a stacked branch by hand means git branch -m, fixing the stack metadata, and then on GitHub either renaming the branch or pushing a new one and opening a new PR. Easy to end up with a PR on a branch that no longer exists locally.

git stack rename <name> (and git rename) renames the current branch, keeping its place, commits and base. If it's been pushed, it's renamed on GitHub first, through GitHub's branch rename API. That keeps the PR attached and retargets the PRs based on it, and if GitHub refuses (offline, no permission, name taken) nothing local has changed yet. Then the local branch and its record in the stack metadata are renamed in place, so the PR record survives, and the remote tracking ref and upstream follow. --local renames only on your machine, with a notice that the PR stays on the old name. Agents get stack_rename.

One thing to watch: if GitHub accepts the rename but something local then fails, GitHub isn't reverted. The error says what state things are in.

Renaming a stacked branch by hand means git branch -m, then fixing the gh stack file so the stack still knows about it, then renaming it on GitHub so its PR doesn't get orphaned. None of the pieces for doing that properly existed yet.

So the forge port gets RenameBranch, which the GitHub adapter does through GitHub's branch rename endpoint (that keeps the PR attached and retargets PRs based on the branch, which deleting and pushing again wouldn't). The git client gets a plain branch rename, and a metadata Update can now rename a branch in place: set its new name and RenamedFrom, and the gh stack backend reuses the old record under the new name, so the PR record and anything we don't model come along.
Once a branch is in a stack there was no sane way to change its name. git branch -m loses it from the stack, and once it's pushed the PR stays behind on the old name, so you'd end up closing it and opening a new one.

So git stack rename <name> (and git rename) renames the current branch and keeps its place in the stack, its commits and its PR; nothing is rebased, the branch above just sits on the new name. If the branch has been pushed it's renamed on GitHub first, so if GitHub says no (offline, no permission, name taken) nothing here has changed and the error points at --local. Then the local branch and the stack record follow, the upstream and remote tracking ref move to the new name, and the cached PR list is dropped since it still names the old branch.

--local renames only this copy. The PR stays on the old name and the next submit opens a new one, which a notice says. It refuses on a trunk, an untracked branch, a merged one, during a rebase, or when the name is already taken here or on the remote. Agents get the same thing as stack_rename.
@DomBlack
DomBlack added this pull request to stack #59 October 16, 2026 13:30
@DomBlack DomBlack changed the title rename Add git stack rename Oct 16, 2026
@DomBlack DomBlack added the enhancement New feature or request label Oct 16, 2026
@DomBlack
DomBlack merged commit f3a2e3a into main Oct 16, 2026
5 checks passed
@DomBlack
DomBlack deleted the rename branch October 16, 2026 13:45
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.

1 participant