Renaming Local and Remote Branches in Git

- 2 minutes read

Renaming branches in Git is quite straightforward, but the approach varies based on whether you want to rename a local or remote branch.

First, let’s rename a local branch. To list all of your local branches, you can run the following command:

git branch --list

If you haven’t already, you can then select the local branch you want to rename using the checkout command, replacing old with the name of the branch you want to rename:

git checkout old

Once you’ve selected the right branch, you can rename it with the following command, swapping out new for the new name.

git branch -m new

Link to this section Renaming a remote branch

If you want to rename a remote branch, you’ll have to first complete the previous steps, renaming the branch locally.

Once you’ve done that, you can delete the old branch, replacing old with the name of the branch you want to delete:

git push origin --delete old

Lastly, just push the new name and set it as the upstream branch, replacing new with the new branch name:

git push origin -u new

Link to this section Conclusion

Renaming branches is generally fairly simple. Just be sure to always double-check your spelling, because trying to undo those pesky spelling mistakes can waste time.

Happy renaming!