I don't want to rename a remote branch, as described in Rename master branch for both local and remote Git repositories.
How can I rename a local branch which hasn't been pushed to a remote branch?
In case you need to rename remote branch as well:
How to rename a remote git branch name
The above command will change your branch name, but you have to be very careful using the renamed branch, because it will still refer to the old upstream branch associated with it, if any.
If you want to push some changes into master after your local branch is renamed into new_branch_name (example name):
git push origin new_branch_name:master
(now changes will go to master branch but your local branch name is new_branch_name)For more details, see "How to rename your local branch name in Git."
PHPStorm:
To rename a branch locally:
Now you'll have to propagate these changes on your remote server as well.
To push changes of the deleted old branch:
To push changes of creation of new branch:
Here are three steps: A command that you can call inside your terminal and change branch name.
If you need more: step-by-step, How To Change Git Branch Name is a good article about that.
Trying to answer specifically to the question (at least the title).
You can also rename local branch, but keeps tracking the old name on the remote.
Now, when you run
git push
, the remoteold_branch
ref is updated with your localnew_branch
.You have to know and remember this configuration. But it can be useful if you don't have the choice for the remote branch name, but you don't like it (oh, I mean, you've got a very good reason not to like it !) and prefer a clearer name for your local branch.
Playing with the fetch configuration, you can even rename the local remote-reference. i.e, having a
refs/remote/origin/new_branch
ref pointer to the branch, that is in fact theold_branch
onorigin
. However, I highly discourage this, for the safety of your mind.For Git GUI users it couldn't be much simpler. In Git GUI, choose the branch name from the drop down list in the "Rename Branch" dialog box created from the menu item Branch:Rename, type a New Name, and click "Rename". I have highlighted where to find the drop down list.