Locally and Remotely Renaming a Branch in Git
Let's say you're busy working on your project, creating feature branches right and left to build out your super sweet app. Then your dev team decides to change their feature branch naming convention. How do you proceed without having an aneurysm? Can you easily accomodate your team's plan and not end up wanting to punch people in the face? Yep! As a matter of fact it's super simple to rename your branches. Here's how.
Let's say you have an existing branch called "my-hot-feature," and you want to rename it to "feature-15."
First, you want to change your local branch. This couldn't be easier:
git branch -m my-hot-feature feature-15
Then, you want to change the remote branch. This is a bit more complex, because you can't directly rename the remote branch. Instead you have to delete the remote branch with the old name, and recreate it with the new name. You need to start by getting the remote name:
git remote -v
This should give you something like this:
origin https://github.com/benjaminlhaas/Yii-with-Users-and-Rights (fetch)
origin https://github.com/benjaminlhaas/Yii-with-Users-and-Rights (push)
The remote name here is "origin." So now that you know this, you can delete and re-create the remote branches.
Delete the remote branch with the old name:
git push origin :my-hot-feature
Re-create the remote branch with the new name:
git push origin feature-15
(Note: this is only recommended if you don't have any other users working on this branch, or if you coordinate in advance with them. Check out this StackOverflow post for more info on the impact of renaming.)
That's all there is to it. Now enjoy your free time and go get an early lunch.