Skip to content

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

Closed

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.

Activity

  1. self-assigned this
    on Jun 25, 2025
  2. love-linger commented on Jun 25, 2025

    @love-linger
    Collaborator

    I've pushed a new commit that allows to use input controls (TextBox, PathSelector or CheckBox) in custom actions.

    You can do this via custom action.

  3. goran-w commented on Jun 25, 2025

    @goran-w
    ContributorAuthor

    Hmm... Sure, we can do a lot of things via Custom Actions, and the new action-input feature is great!

    But in this specific case, having a Rename <branch> command on remote branches would have been very consistent with the already existing command on local branches. 🤔 I still think this could be made part of the built-in functionality, instead of having every user implement their own version of it. (Renaming a remote branch is not a super uncommon thing to do, but still tricky to remember exactly how to do it via git push...)

    Anyway, there is currently no way to add a Custom Action for a Tag, which would be needed if I want to implement a custom Rename tag action! Could that be added, as a new action-Scope, along with its own related variable ${TAG} containing the name of the selected Tag?

  4. love-linger commented on Jun 25, 2025

    @love-linger
    Collaborator

    Never seen a git client provides such feature. Deleting remote branch is a very dangerous action. It should not be combined with other operations.

  5. goran-w commented on Jun 25, 2025

    @goran-w
    ContributorAuthor

    Never seen a git client provides such feature. Deleting remote branch is a very dangerous action. It should not be combined with other operations.

    I see your point, but it's not much worse (or more dangerous) than force-pushing a branch. Deletion of the original branch should only be done after verifying that the new (renamed) branch was successfully pushed and is identical.

  6. love-linger commented on Jun 25, 2025

    @love-linger
    Collaborator

    A new scope Tag was added.

  7. goran-w commented on Jun 25, 2025

    @goran-w
    ContributorAuthor

    Thanks, that's great! I'll close this request now, to get working on Custom Actions... 😅

  8. goran-w commented on Jun 26, 2025

    @goran-w
    ContributorAuthor

    Never seen a git client provides such feature. Deleting remote branch is a very dangerous action. It should not be combined with other operations.

    Hmm, well, this is actually (boasted as) a feature in the (commercial) Tower git-client:
    https://www.git-tower.com/learn/git/faq/git-rename-branch

    Watch the short video in the "Tip - Renaming Branches in Tower" box on the linked page! 😉

    "In case you are using the Tower Git client, you can rename both local and remote branches simply from the contextual menu (no need to delete and re-push anything)."

  9. goran-w commented on Jun 30, 2025

    @goran-w
    ContributorAuthor

    Tip for a Custom Action - if a remote branch is on GitHub, the following GitHub CLI (API) command can be used to rename it (needs to be called from within a local clone) :

    gh api repos/{owner}/{repo}/branches/<old_name>/rename -F new_name=<new_name>

    This one-liner is much simpler to setup in a Custom Action, compared to using a Git Bash script (or similar) to perform the remote renaming using git push, but it will only work for GitHub and only if GH authentication etc via CLI is already setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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