How to Rename Local and Remote Branches in Git

How to Rename Local and Remote Branches in Git
How to Rename Local and Remote Branches in Git

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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here