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




Related Posts

What is the Difference Between Git Pull and Git Fetch

Short answers to the question what is the difference between...

How to Revert a Git Repository to a Previous Commit

Short answers to the question how to revert a git...

How to Modify Existing Unpushed Commit Messages

Short answers to the question how to modify existing unpushed...

How to Undo a Git Add Before Commit

Short answers to the question how to undo a git...

How to Rename a Local Git Branch

Short answers to the question how to rename a local...

How to Delete a Git Branch Locally and Remotely

Short answers to the question how to delete a git...