Renaming a branch while on pull request

Update (Oct 2021):

Check out this answer

Original answer (Jan 2018):

Short Answer:

No

Alternative approach:

  1. Open a new PR with a new (renamed) branch
  2. Close the old PR referencing the new one (e.g. Closed in favor of #new_pr_id)
  3. Modify the description of the new PR (e.g. Supersedes #old_pr_id)
  4. (optional) Make a comment about the relevant discussion on the old PR

Note:

The name of a remote branch (constituting a PR) needed to change because the build system needed the branch's name that ends with the ticket ID. However, the PR was opened prior to official ticket creation (from specs) and had contained valuable discussion. The described approach was the only way to make build system work, and also not lose any information (although there was an extra step in tracking it).


"Renaming" a remote branch in git, as indicated by the link you provided, is really just deleting a branch, followed by pushing a new one with the same commit hash but a new name. If you have a pull request open for branch patch-1, when you delete that branch, the pull request will be closed.

So, no you can't rename the branch with a pull request open without deleting the branch and removing the pull request. However, there's nothing stopping you from doing that, pushing a new branch with a new name, and creating a new pull request.