How do I rename a local Git branch?

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

    git branch -m old_branch_name new_branch_name
    

    The above command will change your branch name, but you have to be very careful using the renamed branch, because it will still refer to the old upstream branch associated with it, if any.

    If you want to push some changes into master after your local branch is renamed into new_branch_name (example name):

    git push origin new_branch_name:master (now changes will go to master branch but your local branch name is new_branch_name)

    For more details, see "How to rename your local branch name in Git."

提交回复
热议问题