Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create 2019-06-09.how-do-i-delete-a-git-branch-locally-and-remotely.md #4

Merged
merged 1 commit into from Jun 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -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>
```