Let's say you start working on a task and create a branch with the same name. But as you progress further, you realise that the work itself doesn't describe the task name or the nature of work changes in between. However, you have already pushed your changes on remote.
How do you rename the branch both locally and remotely?
- git checkout <old_name>
- git branch -m <new_name>
- git push origin -u <new_name>
- git push origin --delete <old_name>
There are also different ways of achieving the same outcome. For example, this gist does it in fewer lines.
You can also use GUI tools to achieve the same outcome in few clicks.