If you want to rename a branch while pointed to any branch, do:
git branch -m <oldname> <newname>
If you want to rename the current branch, you can do:
git branch -m <newname>
A way to remember this is -m is for “move” (or mv), which is how you rename files.
If you are on Windows or another case-insensitive filesystem, and there are any capitalization change in the name, you need to use -M, otherwise, git will throw branch already exists error:
git branch -M <newname>
- 1How to Install Git on Ubuntu 18.04?
- 1Which is the right way to reflect already pushed changes to local branch?
- 1SVN vs Git: Which One Is Best For Your Needs
- 1How make git commands shorter
- 5How can I rename git local and remote branch name?
- 1Git - clone another project branch to current project
- 1How to check does a specific branch contains a given commit in Git
- 1Remove files from Git commit
- 1Differences between 'git pull' and 'git fetch'?
- 2How to get the current branch name in Git?
- 1How to remove Git branch locally and remotely?