You are working on a project and the team has defined a naming convention for git branches. You have created a branch and pushed all your changes then realized that your branch name has Uh o in it. You have to rename the branch. Git made it very easy for you to rename the branch using -m command. Follow these steps_

Checkout the branch.
gitcheckoutOld_BranchName
Rename the local branch.
gitbranch -mNew_BranchName
Push the new local branch and reset the upstream branch.
gitpush origin -uNew_BranchName
Safely delete the old remote branch.
gitpush origin --deleteOld_BranchName
Or
gitpush origin:Old_BranchName
That’s it, renaming is done for local and remote Git branch.
You can also rename the branch from another branch using these commands.
gitbranch -mOld_BranchName New_BranchName
gitpush origin:Old_BranchName
gitpush origin -uNew_BranchName
Happy coding!
No comments:
Post a Comment