Naming a git branch incorrectly and pushing it to the origin happens often during continuous integration. Fortunately, there is a way to rename the existing branch without losing all your precious commits. You can use the following steps for successfully renaming the git branch:
1. Renaming Local Branch:
In case you are on the same branch, then use the following git command.
>git branch -m new-branch-name
In case you are on the another branch, then use the following git command.
git branch -m old-branch-name new-branch-name
2. Delete the old-branch-name remote branch and push the new-branch-name local branch:
git push origin :old-branch-name new-branch-name
3. Reset the upstream branch for the new-branch-name local branch:
Move to the branch and then, enter the following command
git push origin -u new-branch-name
Note: Please don't forget to pull the latest code before making any changes.