This should help in cases where you create a git branch and publish to the remote repository but realize it’s an incorrect naming convention or name for the branch. You can use the steps below to rename the published branch to a new format or name. You can’t just rename the git branch in the repository. you must check out, rename the branch, then push the new name and delete the old. You can use the git renaming feature to rename a branch and push it to the remote repository easily using the git branch -m command When you’re ready to rename the git local and remote branches, follow the steps below:
Switch to the old branch
The first step is to switch to the old branch you want to rename. you can do that by using the command below Replacing old_branch_name with the current branch you want to rename.
Rename the branch
Now that you have checkout the branch you want to rename, simply run the commands below to rename it. Replacing new_branch_name with the new branch you want to public The steps above rename a git branch
Delete the old branch and push a new branch
Step 1 and 2 shows you how to rename a local branch. However, if you have already published an incorrect git branch to the remote repository, simply run the commands below to delete the incorrect name. The public the new name using the commands below This is how you rename a local branch and remote branch using the git branch -m command. Conclusion: You have successfully learned how to rename the git local and remote branches. With it, you can just rename a branch already on the remote repository. you will have to delete the old one and publish the new one. You may also like the post below: