I found the answers here a bit off target, or somewhat sparse, so I thought I'd track a branch re-name and provide a full answer. This solution is carried out entirely on the local command line.
So, as per the OP, if a local branch is pushed to origin, but is not yet merged, it can still be renamed, and the remote branch deleted, so the local branch can be pushed to replace it under the new name.
Let's say the branch to be renamed is feature/old_name and the new name is feature/new_name.
First of all just check where you are. Sometimes I think I'm still on a particular branch, when I'm not, or I forget I should be on a particular branch to do the operation, so it's good practice to just check where you are:
$ git status
# On branch feature/old_name
nothing to commit, working directory clean
To list all available branches, just to orientate:
$ git branch
feature/some_name
* feature/old_name
master
If you're not on the branch you want to rename, make sure you are:
$ git checkout feature/old_name
Already on 'feature/old_name'
Then just rename the local branch with the -m option. For the local branch, it's that simple:
$ git branch -m feature/new_name
Now to check the remote tracking, issue a "very verbose" branch request, and observe the branch that's just been renamed is still tracking on the remote under it's old name:
$ git branch -vv
feature/some_name fc0ec55 [origin/feature/some_name] Some commit message
* feature/new_name a64af75 [origin/feature/old_name] Previous commit message
master 3a0c732 [origin/master] Another commit message
So now it's necessary to delete the remote tracking branch with the old name altogether. The branch with the new name is still checked out:
$ git status
# On branch feature/new_name
nothing to commit, working directory clean
$ git push origin --delete feature/old_name
- [deleted] feature/old_name
If you check on your online web GUI (GitLab, GitHub, BitBucket...) you should find the old_name remote branch, and it's commits, are gone.
But looking locally now, the local tracking doesn't actually know the remote branch has gone yet:
$ git branch -vv
feature/some_name fc0ec55 [origin/feature/some_name] Some commit message
* feature/new_name a64af75 [origin/feature/old_name] Previous commit message
master 3a0c732 [origin/master] Another commit message
So to make it all happen, push the local branch to origin, under its new name:
$ git push -u origin feature/new_name
Counting objects: 21, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (14/14), done.
Writing objects: 100% (14/14), 2.46 KiB | 0 bytes/s, done.
Total 14 (delta 11), reused 0 (delta 0)
remote: Create pull request for feature/new_name:
* [new branch] feature/new_name -> feature/new_name
Branch feature/new_name set up to track remote branch feature/new_name from origin.
And confirm:
$ git status
# On branch feature/new_name
nothing to commit, working directory clean
$ git branch -vv
feature/some_name fc0ec55 [origin/feature/some_name] Some commit message
* feature/new_name a64af75 [origin/feature/new_name] Previous commit message
master 3a0c732 [origin/master] Another commit message
The branch should now be available on your remote under the new name.
I haven't tested the scenario where someone else has also pushed commits to the remote branch, but as long as you pull the branch before carrying out this sequence, I believe that should also work.
If you're in doubt (git is sometimes like that) you can always zip your local repo first, and keep it out of the way somewhere, so that you can at least restore locally, even by copying in the old files to the repo if necessary ;-)