Linux

Tutorial To Rename A Git Branch | Git Tutorial

Tutorial To Rename A Git Branch | Git Tutorial

Insight: How To Rename a Git Branch

 

In this tutorial post, we will show you the method to rename a git branch. Sometime we need to renamge a git branch after creating a new branch and pushing to the remote repository. Git allows us to rename the branch and we can do it using the -m option.

It’s pretty easy to rename a local Git branch but if you want to rename a remote Git branch then you delete it at first and then re-push the renamed local branch.

Let’s see the process to rename a local and remote Git branch.

Tutorial To Rename A Git Branch

Rename a local and remote Git branch

You need to follow the steps explained below to rename a Local and Remote Git Branch.  At first, you need to switch to the local branch, that local branch which you are going to rename:

git checkout <old_branchname>

Rename the local branch with the following command:

git branch -m <new_branchname>

Run this command if you have already pushed the <old_name> branch to the remote repository. You need to delete the <old_name> remote branch:

git push origin --delete <old_name>

Now, push the <new_name> local branch. After pushing the new name, you need to reset the upstream branch too.