This will be a very short post, and like the other git posts is meant primarily for me to remember a git command which I seldom use, but when I do, I never remember the exact syntax.
As they say:
If you want to remember somethinng, write it down
To do this you will need to use the
branch command with the
-m option and will have to specify the new name.
Renaming the current branch:
$ git branch -m <new-name>
Renaming a different branch:
$ git branch -m <old-name> <new-name>
<new-name> already exists you will need to use the
-M option instead to force the rename.
If you have not previously pushed the old branch to your remote git repo then you can simply push like you would normally
git push -u origin <new-name>
If instead you have previously pushed the old branch, then the simplest solution is to first delete the old branch and then push the new one.
$ git push origin --delete <old-name>
Or you can use the short form.
$ git push origin :<old-name>
And then push the new branch and add upstream tracking reference.
$ git push -u origin <new-name>