How do I rename a local Git branch?
Stack How?
Stackorigin – The Community of Question and Answers Latest Articles
Read More About Python List Comprehension with examples
Python List Comprehension: Python List comprehension provides a much more short syntax for creating a new list based on the values of an existing list. Advantages of List Comprehension in Python: Time Efficient than loop Space Efficient than loop Needs ...
Do not accept an offer letter from companies.
Do not accept an offer letter from companies without verifying the following points. Designation Salary Details & CTC Distribution Leave Policies Working Hours & Days Medical Coverage/Insurance Probation Period Notice Period Benefits and Perks Bonus F&F Policy
How to call API using Ajax
AJAX stands for Asynchronous JavaScript and XML and its used for to make calls to the server to fetch some data. In this article, we will learn how to implement a simple API call using AJAX technology. How to use GET ...
If you want to rename a branch while pointed to any branch, do:
If you want to rename the current branch, you can do:
If you want to push the local branch and reset the upstream branch:
And finally if you want to Delete the remote branch:
A way to remember this is
-m
is for “move” (ormv
), which is how you rename files. Adding an alias could also help. To do so, run the following:If you are on Windows or another case-insensitive filesystem, and there are only capitalization changes in the name, you need to use
-M
, otherwise, git will throw branch already exists error: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.”
To rename your current branch:
Here are the steps to rename the branch:
git branch -m <new_name>
git push origin :<old_name>
git push origin <new_name>:refs/heads/<new_name>
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:
Git version 2.9.2
If you want to change the name of the local branch you are on:
If you want to change the name of a different branch:
If you want to change the name of a different branch to a name that already exists: