Rename local and remote branch in git

Sometimes you need to change a branch name that you already pushed to the remote server. To rename a remote branch follow these steps.

1- checkout your branch

git checkout old-branch-name

2- rename the branch locally

git branch -m new-branch-name

3- Delete the old-branch-name branch and poush the new-branch-name branch

git push origin :old-branch-name new-branch-name

4- Change the upsdtream branch to new-branch-name

git push origin -u new-branch-name