How do I delete a Git branch locally and remotely?
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 ...
Delete Local Branch
To delete the local branch use one of the following:
-d
option is an alias for--delete
, which only deletes the branch if it has already been fully merged in its upstream branch.-D
option is an alias for--delete --force
, which deletes the branch “irrespective of its merged status.” [Source:man git-branch
]git branch -d
(delete) learned to honor the-f
(force) flag.Delete Remote Branch
As of Git v1.7.0, you can delete a remote branch using
which might be easier to remember than
which was added in Git v1.5.0 “to delete a remote branch or a tag.”
Starting with Git v2.8.0, you can also use
git push
with the-d
option as an alias for--delete
. Therefore, the version of Git you have installed will dictate whether you need to use the easier or harder syntax.To remove a local branch from your machine:
git branch -d {the_local_branch}
(use-D
instead to force deleting the branch without checking merged status)To remove a remote branch from the server:
git push origin --delete {the_remote_branch}
The short answers
If you want more detailed explanations of the following commands, then see the long answers in the next section.
Deleting a remote branch
Deleting a local branch
It’s very simple:
To delete the remote branch
Or
— You can also delete tags with this syntax
To forcefully delete local branch
If you want to delete a branch, first checkout to the branch other than the branch to be deleted.
Deleting the local branch:
Deleting the remote branch:
Delete locally:
To delete a local branch, you can use:
To delete a branch forcibly, use
-D
instead of-d
.Delete remotely:
There are two options:
To delete your branch locally and remotely
git checkout master
git push origin --delete <branch-name>
git branch --delete <branch-name>