Rename Local and Remote Git branch

Today we’ll go through a few of the very simple steps to rename Git branches which maybe present locally or on a remote server.

We will use the below command to rename branches:

git branch

Rename Local git branch

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

git branch -m <new_name_for_current_branch>

To rename another branch than your current one

git branch -m <old_branch_name> <new_branch_name>

Now, if you have pushed the branch to remote server. You can do the following:

// Delete the old branch from remote server
git push origin :<old_branch_name>
// Push new branch to remote server
git push -u <remote> <new_branch_name>

And, that’s it!

Happy Git-ing! 🙂

Leave a comment

Your email address will not be published. Required fields are marked *