How to delete a local (and remote) Git branch - Rocketeers

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com) 

 On this page

 Knowledge
---------

How to delete a local (and remote) Git branch
=============================================

### [\#Development](https://rocketee.rs/index.php/development)

Deleting a branch locally uses git branch -d, with a capital -D to force it. Deleting it on the remote is a separate command that people often forget.

 Published by [Mark van Eijk](https://rocketee.rs/index.php/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [Delete a local branch](#content-delete-a-local-branch)
2. [Delete the remote branch](#content-delete-the-remote-branch)
3. [Clean up stale remote-tracking branches](#content-clean-up-stale-remote-tracking-branches)

[\#](#content-delete-a-local-branch "Permalink")Delete a local branch
---------------------------------------------------------------------

Use `-d` (lowercase) to delete a branch that has already been merged. Git refuses if the branch has unmerged commits, which protects you from losing work:

 ```
git branch -d feature-login

```

If you are sure you want to discard the branch even though it is not merged, force it with `-D`:

 ```
git branch -D feature-login

```

You cannot delete the branch you are currently on. Switch away first:

 ```
git switch main
git branch -d feature-login

```

[\#](#content-delete-the-remote-branch "Permalink")Delete the remote branch
---------------------------------------------------------------------------

Removing the branch locally does not touch the remote. Delete it there explicitly:

 ```
git push origin --delete feature-login

```

An older shorthand does the same thing (note the leading colon):

 ```
git push origin :feature-login

```

[\#](#content-clean-up-stale-remote-tracking-branches "Permalink")Clean up stale remote-tracking branches
---------------------------------------------------------------------------------------------------------

After a branch is deleted on the remote, your local clone may still show it under `git branch -r`. Prune those references:

 ```
git fetch --prune

```

To rename a branch instead of deleting it, see [How to rename a Git branch](/git-rename-branch).

### Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Development](https://rocketee.rs/index.php/development)

- [Install PHP memcached extension on macOS](https://rocketee.rs/index.php/install-php-memcached-extension-on-macos)
- [Fix: Cannot connect to the Docker daemon at unix:///var/run/docker.sock](https://rocketee.rs/index.php/cannot-connect-to-docker-daemon)
- [git stash pop vs apply: save and restore changes](https://rocketee.rs/index.php/git-stash-pop)
- [How to clean up Docker with prune (images, volumes, system)](https://rocketee.rs/index.php/docker-prune)
- [What port does SSH use (and how to change it)](https://rocketee.rs/index.php/ssh-port)
- [How to checkout a Git tag](https://rocketee.rs/index.php/git-checkout-tag)

 [View all 12 articles →](https://rocketee.rs/index.php/development)
