How to Rename Local and Remote Branches in Git

Table of Contents
Rename Local and Remote Branches in Git
Sometimes when you need to rename a local or remote branch in Git. There may be any concerns like incorrectly followed conventions or project needs. In this tutorial, you are going to learn how to rename local or remote branches in Git. You can rename a git branch very easily by using this tutorial.
Basic Syntax for Renaming Git Branch
You can rename your branch in Git by using git branch
command followed by -m
option.
If you want to change the current local branch name then you can use the following syntax:
git branch -m NEW_NAME
If you want to change the different local branch name then you can use the following syntax:
git branch -m OLD_NAME NEW_NAME
Rename Git Brach
Now follow the below steps to rename local git branch. These steps can also be used to rename the remote git branch.
If you are not on the branch that you want to rename, then change your branch by using the following command by replacing BRANCH_NAME
with the branch name which wants to rename:
git checkout BRANCH_NAME
Next, rename the local branch name by replacing NEW_NAME with new branch name in the following command:
git branch -m NEW_NAME
Now delete the old remote branch if you already pushed it by using the following command:
git push origin --delete OLD_NAME
Next push all the changes to the new branch name by using the following command:
git push origin -u NEW_NAME
Conclusion
You have successfully learned How to Rename Local and Remote Branches in Git. If you have any queries please don’t forget to comment out.
LATEST POSTS
-
How to Install Opera Browser on Debian 10
-
How to Install Node.js with npm on Debian 10
-
How to Install Apache Tomcat 9 on Ubuntu 18.04
-
How to Disable SELinux on CentOS 8
-
How to install Krita on Ubuntu 18.04
-
How to Safely Remove Files and Directories Using Linux Command Line
-
How to Install Deepin Desktop Environment on Ubuntu 18.04
-
How to Add Swap Space on CentOS 8
-
How to Create Sudo User on CentOS
-
Concatenate Strings in Bash Script
-
How to Install Papper Flash on Ubuntu
-
How to Use SCP Command to Transfer Files/Folders in Linux