Cheat Sheets · Git Cheat Sheet · Git Delete a Branch — Local and Remote
Git Delete a Branch — Local and Remote
git branch -d <name>Delete — refuses if the branch has unmerged work
git branch -D <name>Force delete — even with unmerged work (the work becomes unreachable)
git branch -aList all branches, local and remote-tracking
Local branches
| Command | Effect |
|---|---|
git branch -d <name> | Delete — refuses if the branch has unmerged work |
git branch -D <name> | Force delete — even with unmerged work (the work becomes unreachable) |
git branch -a | List all branches, local and remote-tracking |
Remote branches
| Command | Effect |
|---|---|
git push origin --delete <name> | Delete the branch on the remote |
git fetch --prune | Clean up local references to remote branches that were deleted elsewhere |
Deleting a branch removes a pointer, not (usually) commits — Git garbage-collects commits only when they become unreachable.
Related Git recipes
FAQ
-d refused my delete — why?
The branch contains commits not merged anywhere. If you are certain they are worthless, -D overrides; otherwise merge or rebase first.
The branch still shows after deletion — why?
Your local remote-tracking reference is stale. git fetch --prune (or git remote prune origin) syncs the list.
Can I delete main/master?
Git will refuse the branch you are on; the remote side is usually protected by the host. Feature branches are the ones meant to be deleted.
Stop memorizing — build it interactively
Generate branch commands in the Git BuilderFull reference: Git Cheat Sheet