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_
![Rename Git Branch Rename Git Branch](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtAL7JIJx6G7VUN0Uhxd544vZqvCDKmnJsd-B3xRPTwbpo-2jSCH9SwjIoXIUQPf8bdFRxh6D6rNUe6T6a89LT8pQ_FzxnK1skRUrJzRaHrhlDIIkWfAglJPOvVYTcvEa8IziPSRmVdmQ/s400/Git-Logo-1788C.png)
Checkout the branch.
git
checkout
Old_BranchName
Rename the local branch.
git
branch -m
New_BranchName
Push the new local branch and reset the upstream branch.
git
push origin -u
New_BranchName
Safely delete the old remote branch.
git
push origin --delete
Old_BranchName
Or
git
push 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.
git
branch -m
Old_BranchName New_BranchName
git
push origin
:Old_BranchName
git
push origin -u
New_BranchName
Happy coding!
No comments:
Post a Comment