# Git: Delete a Local and Remote Branch Command

> Delete a local Git branch with git branch -d or -D for unmerged branches, then remove the matching remote branch using git push --delete

**URL:** https://sentry.io/answers/delete-a-git-branch-locally-and-remotely/

---

## The Problem

How do I delete a Git branch locally and remotely?

## The Solution

First, ensure that the repository is not currently on the branch to be deleted:

```sh
git checkout main
```

To delete a local branch that has been fully merged, you can use `git branch -d`:

```sh
git branch -d branch-to-delete
```

To delete a local branch that has not been fully merged (i.e. force delete), you must use `git branch -D`:

```sh
git branch -D branch-to-delete
```

To delete a remote branch, use `git push --delete`. Assuming that the remote is named `origin`, you would use the command:

```sh
git push origin --delete branch-to-delete
```

---

*Source: [sentry.io/answers/delete-a-git-branch-locally-and-remotely/](https://sentry.io/answers/delete-a-git-branch-locally-and-remotely/)*
