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 Rename Local 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>
Git Rename Remote branch
Now, if you have pushed the branch to remote server. You can do the following:
// Delete the old_branch_name branch from remote server, that you just renamed previously above in the post git push origin :<old_branch_name> // Now, push the new_branch_name to remote server git push -u <remote> <new_branch_name>
And, that’s it!
Happy Git-ing! 🙂