Renaming git branch on local or remote repository
Last Modified at 2019-06-25 21:29:26
In some cases, like you named branch incorrectly and pushed this to remote server or your project name has been changed to some other name you want to rename branch name then this tutorial is going to show you how to rename git branch repository very easily.
To make this happen you will need to follow below steps:
Rename your local branch:
If you are on the same branch that you want to rename then run below command:
git branch -m new-branch-name
In above command, i have renamed my current branch name to 'branch-new-name'. You will have to change it as per your requirement.
In case you are on A
branch you want to rename B
branch as C
then run below command:
git branch -m B C
Now is the time to delete old branch name and push the new local branch:
git push origin :B C
To reset upstream branches so that they can update new branch name as well:
git push origin -u C
I hope this small trick will help you a lot. Please do let me know your feedback on the comment section below.