How to rename a local and remote Git branch
๐
August 20, 2021
๐Git
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
- Using tags in Git
- Delete all commit history in GitHub
- Multiple SSH keys for different GitHub accounts
- Undo commit before push in 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.
git checkout <old_branch_name>
</old_branch_name>
2. Rename the local branch
Run the following command to rename the local branch.
git branch -m <new_branch_name>
</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.
git push origin -u <new_branch_name>
</new_branch_name>
4. Delete the old remote branch
At last, delete the old remote branch by running the following command.
git push origin --delete <old_branch_name>
</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..!! ๐