Knowledge
How to delete a local (and remote) Git branch
#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 on June 23, 2026 · 1 minute read
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
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
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. To check out a tagged release without deleting anything, see how to check out a Git tag.
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!