How do I rename a local Git branch?

后端 未结 30 1529
轻奢々
轻奢々 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:20

    Here are the steps to rename the branch:

    1. Switch to the branch which needs to be renamed
    2. git branch -m
    3. git push origin :
    4. git push origin :refs/heads/

    EDIT (12/01/2017): Make sure you run command git status and check that the newly created branch is pointing to its own ref and not the older one. If you find the reference to the older branch, you need to unset the upstream using:

    git branch --unset-upstream
    

提交回复
热议问题