How to Delete a Git Branch Both 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 ...
Deleting a branch LOCALLY
Git will not let you delete the branch you are currently on so you must make sure to checkout a branch that you are NOT deleting. For example:
git checkout main
Delete a branch with
git branch -d <branch>
.For example:
git branch -d fix/authentication
The
-d
option will delete the branch only if it has already been pushed and merged with the remote branch. Use-D
instead if you want to force the branch to be deleted, even if it hasn’t been pushed or merged yet.The branch is now deleted locally.
Deleting a branch REMOTELY
Here’s the command to delete a branch remotely:
git push <remote> --delete <branch>
.For example:
git push origin --delete fix/authentication
The branch is now deleted remotely.
You can also use this shorter command to delete a branch remotely:
git push <remote> :<branch>
For example:
git push origin :fix/authentication
If you get the error below, it may mean that someone else has already deleted the branch.
Try to synchronize your branch list using:
The
-p
flag means “prune”. After fetching, branches which no longer exist on the remote will be deleted.