Git Rename Local and Remote branch

Rename local and remote git branch

Today we’ll go through a few of the very simple steps to rename local branch and rename a remote branch in Git.

We will use the below command to rename branches:

git branch

Git Rename Local branch

In Git you can rename the Currently active local branch and also the other branches that you are not currently working on.

Git rename local branch: Current

To rename a local branch (which is also the currently active branch, the one on which you are currently present on, and the one which HEAD ref is pointing to).

git branch -m <new_name_for_current_branch>

Git rename local branch: Other

To rename another local branch than the currently active one

git branch -m <old_branch_name> <new_branch_name>

Git Rename Remote branch

Now, since you have already pushed the branch to remote server, and you want the renamed local branch name changes to show up on the remote server. You can do the following:

Delete Old branch from Remote

First we need to Delete the old_branch_name from remote server, which was renamed

git push origin :<old_branch_name>

Push New Branch to Remote

Now, push the new_branch_name to the remote server

git push -u <new_branch_name>

And, that’s how you rename local branch and remote branch in Git!

Happy Git-ing! 🙂

Author: Admin

Hello Friends, welcome to Hackerdays.com. I am the Admin of the site. I have worked as a software programmer for 7 years. I have started this site to learn as well as share whatever little knowledge i have gained over the period of time. If you wish to contact me, you can drop in an email to: admin[AT]hackerdays[DOT]com or you can also use the contact page. Thank you and I'll see you around.

Let us know your thoughts: