How to rename a local and remote Git branch

If you have mistyped the name of the Git branch and added it in the remote repository then we can change it with the help of the bunch of the git commands. So in this article, we will show you how to rename a local and remote Git branch.

Steps to rename a local and remote Git branch

  1. Switch to the local branch
  2. Rename the local branch
  3. Push the branch and reset the upstream branch
  4. Delete the old remote branch

1. Switch to the local branch

First of all, switch to the local branch which you want to rename.

2. Rename the local branch

Run the following command to rename the local branch.

3. Push the branch and reset the upstream branch

Now, let’s push the new local branch () and reset the upstream branch.

4. Delete the old remote branch

At last, delete the old remote branch by running the following command.

That’s it. You have successfully renamed the local and remote Git branch.

I hope you find this article helpful.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

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