How do I rename a local Git branch?

后端 未结 30 1639
轻奢々
轻奢々 2020-11-22 11:48

I don\'t want to rename a remote branch, as described in Rename master branch for both local and remote Git repositories.

How can I rename a local branch wh

30条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 12:13

    Rename the branch will be useful once your branch is finished. Then new stuff is coming, and you want to develop in the same branch instead of deleting it and create the new one.

    From my experience, to rename a local and remote branch in Git you should do the following steps.

    Quoting from Multiple States - Rename a local and remote branch in git

    1. Rename your local branch

    If you are on the branch you want to rename:

    git branch -m new-name
    

    If you are on a different branch:

    git branch -m old-name new-name
    

    2. Delete the old-name remote branch and push the new-name local branch

    git push origin :old-name new-name
    

    3. Reset the upstream branch for the new-name local branch

    git push origin -u new-name
    

提交回复
热议问题