How do I rename a local Git branch?

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

    1. Rename

    If it is your current branch, just do

    git branch -m new_name
    

    If it is another branch you want to rename

    git branch -m old_name new_name
    

    2. Track a new remote branch

    - If your branch was pushed, then after renaming you need to delete it from the remote Git repository and ask your new local to track a new remote branch:

    git push origin :old_name
    git push --set-upstream origin new_name
    

提交回复
热议问题