How to Change the Name of a Remote Git Branch

July 17, 2024 / How-to Guide

In this article, you will explore how to rename a remote Git branch.

Unlike a local branch, a remote branch cannot be directly renamed. Instead, you need to push a new branch name to the remote repository and delete the old one.

Follow these steps:

  1. Rename the local branch:
    Use the ‘-m’ option to rename your local branch.
    git branch -m old-name new-name
  2. Push the new branch and remove the old one.
    git push origin –delete old-name
    git push origin -u new-name
  3. Rearrange the upstream branch:
    git push origin :old-name new-name
    git push origin -u new-name
  4. This process allows you to rename a remote Git branch. Additionally, you can easily rename a local Git branch using similar commands.

This method allows you to rename a remote Git branch.

If you encounter any difficulties, please do not hesitate to contact our support staff.

 

Spread the love