How to Rename Remote GIT branch

If you had named a git branch incorrectly and had pushed the branch to remote repository. Follow the steps listed below to rename the remote branch:

  1. Rename the local branch. 

    If you are on the branch then,

    git branch -m <new-name>

    If you are not on the branch then,

    git branch -m <old-name> <new-name>   

  2. Delete the old named remote branch and push new named local branch 

    git push origin :<old-name> <new-name>

    On success, this text will be displayed.

    – [deleted]

    * [new branch] ->

  3. Reset upstream branch for the local branch. 

    git push origin -u <new-name>

    Branch <new-name> set up to track remote branch from origin.
    Everything up-to-date

 

Leave a comment