Repository navigation
Conversation
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.
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.
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>(andgit 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.--localrenames only on your machine, with a notice that the PR stays on the old name. Agents getstack_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.