On This Page
How to Delete a Git Branch (Local and Remote)
Quick Answer: To delete a local branch that has been merged, run git branch -d <branch-name>. To force delete an unmerged local branch, run git branch -D <branch-name>. To delete a remote branch on GitHub/GitLab, run git push origin --delete <branch-name>.
Quick Reference Commands
| Task | Command |
|---|---|
| Delete local merged branch | git branch -d <branch-name> |
| Force delete local unmerged branch | git branch -D <branch-name> |
| Delete remote branch | git push origin --delete <branch-name> |
| Clean up deleted remote branch refs | git fetch --prune |
1. Delete a Local Branch
⚠️ You cannot delete the branch you are currently on. Switch to
mainfirst.
# 1. Switch to a main or base branch
$ git checkout main
# 2. Delete local branch (safe mode — checks if merged)
$ git branch -d feature-login
If the branch contains unmerged work and Git prevents deletion, force delete it with capital -D:
$ git branch -D feature-login
2. Delete a Remote Branch (GitHub / GitLab)
Deleting a local branch does not remove it from your remote server. To delete the branch on origin:
$ git push origin --delete feature-login
3. Prune Stale Remote Branch References
When teammates delete branches on GitHub, your local environment still holds outdated remote reference pointers (origin/feature-login). Clean them up using prune:
# Remove local references to deleted remote branches
$ git fetch --prune
# (or git remote prune origin)
Read our /git-branch and /git-remote tutorials to learn how branch references are stored in .git/refs/.