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.
Checkout more articles on Git
Steps to rename a local and remote Git branch
- Switch to the local branch
- Rename the local branch
- Push the branch and reset the upstream branch
- Delete the old remote branch
1. Switch to the local branch
First of all, switch to the local branch which you want to rename.
1 | git checkout <old_branch_name> |
2. Rename the local branch
Run the following command to rename the local branch.
1 | git branch -m <new_branch_name> |
3. Push the branch and reset the upstream branch
Now, let’s push the new local branch (
) and reset the upstream branch.
1 | git push origin -u <new_branch_name> |
4. Delete the old remote branch
At last, delete the old remote branch by running the following command.
1 | git push origin --delete <old_branch_name> |
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..!! 🙂