How do I rename a local Git branch?

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

    Git version 2.9.2

    If you want to change the name of the local branch you are on:

    git branch -m new_name
    

    If you want to change the name of a different branch:

    git branch -m old_name new_name
    

    If you want to change the name of a different branch to a name that already exists:

    git branch -M old_name new_name_that_already_exists
    

    Note: The last command is destructive and will rename your branch, but you will lose the old branch with that name and those commits because branch names must be unique.

提交回复
热议问题