How to Rename a Local and Remote Git Branch

Sometimes we have mistyped the name of a git branch or we just simply want to change the name of the branch itself. This guide will focus how you can easily rename a local and remote git branch.

Rename a Local and Remote Git Branch

Local

To rename the local branch, make sure you are on the branch you’d like to rename. If not, switch over to the local branch:

git checkout old_branch_name

Then, to change the name of the old branch name, enter the following command:

git branch -m new_name

With this, you have now renamed your local git branch.

Remote

Now that you have renamed your local branch simply push the changes:

git push origin : old_branch_name new_name

Then, let’s reset upstream branch:

git push origin -u new_name

Finally, let’s delete the old remote branch:

git push origin --delete old_branch_name

Summary

In this guide you’ve learned how to easily rename a local and remote git branch.

Leave a Comment