How to Change Branch Name in Git (Local and Remote)

Changing a branch’s name in Git is a common task and fortunately very easy to do.

Changing the name of a local branch:
git -m newBranchName

If you are not on the branch being renamed, you must specify this branch in the command:
git -m oldBranchName newBranchName

There is no direct way to rename a remote branch. You must delete the remote branch and recreate it with the new name. Here is an example of deleting the remote branch, and recreating it with the new name:
git push origin :oldBranchName
git push origin newBranchName

You can do both delete and recreate steps with a single command:
git push origin :oldBranchName newBranchName

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">