How to Rename a Local Git Branch
Scenario A: Rename the Current Branch
1
$ git branch -m <newname>
The above command will:
- Rename the current branch
- The renamed branch will still refer to the old upstream branch associated with it, if any.
Scenario B: Rename a Different Branch (Not the Current Branch)
1
$ git branch -m <oldname> <newname>
The above command will:
- Rename your branch
- The renamed branch will still refer to the old upstream branch associated with it, if any.
Scenario C: Push the Local Branch and Reset the Upstream Branch
1
$ git push origin -u <newname>
The above command will:
- Reset the upstream branch for the new-name local branch