Git rename branch
How to rename a local and remote git branch
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
Rename a local branch
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:
| |
Renaming a different branch:
| |
If <new-name> already exists you will need to use the -M option instead to force the rename.
Rename a remote branch
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.
| |
Or you can use the short form.
| |
And then push the new branch and add upstream tracking reference.
| |