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

 

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s