Skip to content

[Feature] Rename remote branch (and possibly Rename tag as well) #1457

Closed
@goran-w

Description

@goran-w

There is already a Rename <branch> context-command for local branches, but it would be very useful to have one for remote branches as well!

The feature could be implemented like this, for renaming a branch on <remote> from <old_name> to <new_name> :

  • Do a git fetch --prune <remote> <old_name> (to make sure the <remote>/<old_name> branch is up-to-date).
  • Check that <old_name> still exists on <remote> and that <new_name> is not already present there.
  • Create new (renamed) remote copy of the old remote branch:
    • git push <remote> <remote>/<old_name>:refs/heads/<new_name>
  • Delete (unset) old remote branch:
    • git push <remote> :refs/heads/<old_name>

The last two lines can be combined into a single command (but it's safer to error-check the first one before applying the second) :

  • git push <remote> <remote>/<old_name>:refs/heads/<new_name> :refs/heads/<old_name>

If there's a local branch <tracker> that's tracking <remote>/<old_name>, we should change its upstream info to <remote>/<new_name> and probably also rename the local branch (if it still matches <old_name>) :

  • git branch -u <remote>/<new_name> <tracker>
  • git branch -m <tracker==old_name> <new_name>

NOTE: A similar feature could be added (and would be very useful) for renaming tags as well. However, more care is needed for these:

  • Tags are not explicitly distinguished between local and remote.
  • Similar to the Delete <tag> dialog, there could be a checkbox "Rename on remote repositories".
  • When creating a new (renamed) copy of a Annotated tag, we must make sure it retains its Tag-message, GPG signing etc.

Metadata

Metadata

Assignees

Labels

not-plannedIt's not planned in the future

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions