Discovering an Orphaned Branch
git fetch --prune origin
git branch -vv
--prune removes remote-tracking references for branches already deleted on the remote. A real ": gone" annotation on git branch -vv marks a local branch whose remote copy no longer exists.
Merged vs Unmerged, For Real
git branch --merged master
git branch --no-merged master
--merged lists branches whose every commit is already reachable from master — genuinely safe to delete. --no-merged lists the ones that still hold real, unique work.
Deleting What's Genuinely Safe
git branch -d feature/vegan-notes feature/gluten-free-notes experiment/new-idea
git push origin --delete feature/vegan-notes feature/gluten-free-notes experiment/new-idea
git branch -d (lowercase) genuinely refuses to delete a branch with unmerged work — real, built-in protection.
Force-Deleting What's Deliberately Abandoned
git branch -D feature/abandoned-idea
git branch -D feature/old-refactor
git push origin --delete feature/old-refactor
-D (capital) genuinely overrides that protection — reserved for branches a real, deliberate decision has already abandoned.
This block has left real, genuine branches scattered across the project: two already merged and simply never deleted, one abandoned experiment, one genuinely stale refactor, one real feature still honestly in progress, and one whose remote copy someone already deleted without you knowing.
Real branch hygiene means treating each of these differently, not deleting everything in sight or ignoring all of it forever. git fetch --prune, git branch --merged, and git branch --no-merged turn a confusing pile into three real, distinct categories — each with its own correct real cleanup command.
git fetch --prune
Removes local remote-tracking references for branches already deleted on the remote. Confirmed directly in this lab: it reported "[deleted] (none) -> origin/feature/abandoned-idea", and the local branch subsequently showed ": gone" in branch -vv.
git branch --merged / --no-merged
Lists branches whose commits are (or are not) all already reachable from the given branch. Confirmed directly in this lab: --merged master correctly identified the two already-integrated feature branches plus a trivial, content-free experiment branch, while --no-merged correctly flagged the genuinely unfinished and abandoned ones.
git branch -D (force delete)
Deletes a branch regardless of whether its commits are merged anywhere — genuinely overriding the safety check plain -d performs. Confirmed directly in this lab: -d alone would have refused the unmerged abandoned and old-refactor branches; -D deleted them anyway, as a deliberate real decision.
Takeaways
- git fetch --prune reveals branches whose remote copy is already gone, marked ": gone" in branch -vv
- git branch --merged / --no-merged gives git's own real answer for which branches are safe to delete
- git branch -d refuses to delete unmerged work — a real, deliberate safety check, not an inconvenience
- git branch -D overrides that check for branches a real, considered decision has already abandoned