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
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. Adding an alias could also help. To do so, run the following:
git config --global alias.rename 'branch -m'
If you are on Windows or another case-insensitive filesystem, and there are only capitalization changes in the name, you need to use -M
, otherwise, git will throw branch already exists error:
git branch -M <newname>
Just three steps to replicate change in name on remote
as well as on GitHub:
Step 1 git branch -m old_branchname new_branchname
Step 2 git push origin :old_branchname new_branchname
Step 3 git push --set-upstream origin new_branchname
For Git GUI users it couldn't be much simpler. In Git GUI, choose the branch name from the drop down list in the "Rename Branch" dialog box created from the menu item Branch:Rename, type a New Name, and click "Rename". I have highlighted where to find the drop down list.
If you want to:
git branch -m <oldname> <newname>
git push origin: old-name new-name
git commit <newname>
git push origin new_branch_name:master
git status
git checkout
All of the previous answers are talking about git branch -m
. Of course, it's easy to operate, but for me, it may be a little hard to remember another Git command. So I tried to get the work done by the command I was familiar with. Yeah, you may guessed it.
I use git branch -b <new_branch_name>
. And if you don't want to save the old branch now you can execute git branch -D <old_branch_name>
to remove it.
I know it may be a little tedious, but it's easier to understand and remember. I hope it‘s helpful for you.
Another option is not to use the command line at all. Git GUI clients such as SourceTree take away much of the syntactical learning curve / pain that causes questions such as this one to be amongst the most viewed on Stack Overflow.
In SourceTree, right click on any local branch in the "Branches" pane on the left and select "Rename ...".