Today we’ll go through a few of the very simple steps to rename local branch and rename a remote branch in Git.
We will use the below command to rename branches:
Git Rename Local branch
In Git you can rename the Currently active local branch and also the other branches that you are not currently working on.
Git rename local branch: Current
To rename a local branch (which is also the currently active branch, the one on which you are currently present on, and the one which HEAD ref is pointing to).
git branch -m <new_name_for_current_branch>
Git rename local branch: Other
To rename another local branch than the currently active one
git branch -m <old_branch_name> <new_branch_name>
Git Rename Remote branch
Now, since you have already pushed the branch to remote server, and you want the renamed local branch name changes to show up on the remote server. You can do the following:
Delete Old branch from Remote
First we need to Delete the old_branch_name from remote server, which was renamed
git push origin :<old_branch_name>
Push New Branch to Remote
Now, push the new_branch_name to the remote server
git push -u <new_branch_name>
And, that’s how you rename local branch and remote branch in Git!
Happy Git-ing! 🙂