Skip to content

Commit

Permalink
Merge pull request #4 from sahilbhatt92/master
Browse files Browse the repository at this point in the history
Create 2019-06-09.how-do-i-delete-a-git-branch-locally-and-remotely.md
  • Loading branch information
meSingh committed Jun 10, 2019
2 parents a603ad9 + a55810b commit c921aa5
Showing 1 changed file with 44 additions and 0 deletions.
@@ -0,0 +1,44 @@
---
title: How do I delete a Git branch locally and remotely?
category: solving-mistories
tags:
- remove
- branch
- remote
- local
source: https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-locally-and-remotely/2003515#2003515
author: bsahil
---
Git branches are important part of you daily development process.
If you have done coding and merged your branch, then it has should not be the part of your main repository.
But can be used for research purposes for tracking commit history.
It is common practice to remove your branch after a satisfied merge.

### Overall Summary
There are two ways to delete a branch:
```shell
git push --delete <remote_name> <branch_name>
git branch -d <branch_name>
```
**Note:** In most of the cases remote name is always `origin`.

### Delete a Local Branch
To delete a local branch use the following:
```shell
git push --delete <remote_name> <branch_name>
git branch -d <branch_name>
```
**Note:**
* `-d` option for `git branch` command is an alias of `--delete` flag, which deletes the branch if it has already merged in its upstream branch.
* `-D` is also an option `--delete` flag, which deletes the branch "regardless of its merged status."

To delete a remote branch use the following:
```shell
# Delete a Remote Branch As of Git v1.7.0
git push <remote_name> --delete <branch_name>
```
which is easier than remembering
```shell
# this was added in Git v1.5.0 to delete a remote branch or a tag.
git push <remote_name> :<branch_name>
```

0 comments on commit c921aa5

Please sign in to comment.