How do I rename a local Git branch?

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

    I foolishly named a branch starting with a hyphen, and then checked out master. I didn't want to delete my branch, I had work in it.

    Neither of these worked:

    git checkout -dumb-name

    git checkout -- -dumb-name

    "s, 's and \s didn't help either. git branch -m doesn't work.

    Here's how I finally fixed it. Go into your working copy's .git/refs/heads, find the filename "-dumb-name", get the hash of the branch. Then this will check it out, make a new branch with a sane name, and delete the old one.

    git checkout {hash}
    git checkout -b brilliant-name
    git branch -d -- -dumb-name
    

提交回复
热议问题