Git error The branch 'x' is not fully merged
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
Git shows The branch 'x' is not fully merged when you try to delete a branch with git branch -d and Git detects commits that are not reachable from your current branch. This is a safety check to prevent accidental loss of work. The right next step is deciding whether to merge, preserve elsewhere, or intentionally discard those commits after confirming you are comparing against the branch you actually care about.
Why Git Blocks Deletion
git branch -d deletes only when branch tip is fully merged into current HEAD. If branch has unique commits, deletion is blocked.
Check branch divergence:
Lines prefixed with > usually represent commits unique to feature-x.
The current branch matters here. If you run the delete command while checked out on the wrong base branch, Git may warn even though the feature was merged somewhere else.
Confirm Whether Work Is Already Integrated
Sometimes work is integrated through squash merge or cherry pick, so direct ancestry check fails even though content exists.
Useful checks:
git cherry helps identify commits whose patch content is not yet in target branch.
Option 1: Merge Then Delete Safely
If branch changes should be kept, merge first.
This preserves history and satisfies safe deletion condition.
Option 2: Delete Forcefully When Intentional
If you confirm branch can be discarded, force delete:
Do this only after verifying no needed commits remain. Force delete bypasses safety check.
Preserve Backup Before Force Deletion
Before using -D, create a tag or backup branch so recovery is easy.
Then delete original branch if still desired.
Recover If Deleted by Mistake
If branch was removed accidentally, recover through reflog.
Recovery is usually possible unless reflog entries are expired and garbage collection has removed unreachable objects.
Remote Branch Considerations
Local deletion is separate from remote deletion.
Delete remote branch explicitly:
Before remote deletion, confirm no open pull requests or release processes depend on that branch.
If your hosting platform auto-deletes merged branches, align local cleanup with that behavior so teammates do not see conflicting signals about which branches are still active.
Team Workflow Advice
To avoid repeated confusion:
- Use pull requests as merge source of truth.
- Delete feature branches only after PR merged and CI green.
- Keep short retention window for backup tags on high risk branches.
A lightweight policy prevents accidental branch loss and noisy repository history.
Squash Merge Edge Case
If your team squash merges pull requests, original feature commits are not ancestors of main, so Git may still report branch not fully merged. In that case, compare patch content rather than ancestry alone.
If branch commits are already represented through squashed equivalents, force delete can be reasonable after verification and backup tagging.
When in doubt, keep the branch for a short retention period and delete later after release validation. Short retention lowers risk with minimal repository overhead.
Common Pitfalls
- Forcing deletion without checking whether unique commits contain needed work.
- Assuming squash merged branches are always fully merged by ancestry checks.
- Deleting remote branch while colleagues still base work on it.
- Skipping backup tag before destructive deletion on critical fixes.
- Ignoring reflog recovery options after mistaken branch removal.
Summary
- The error is a protective warning about potentially unmerged commits.
- Use divergence checks to understand what would be lost.
- Merge first when commits should be preserved.
- Use force delete only with explicit intent and backup plan.
- Coordinate remote branch deletion with team workflow and PR state.
Related reading
- Git error when trying to push -- pre-receive hook declined
- Git Extensions Win32 error 487 Couldn''t reserve space for cygwin''s heap, Win32 error 0
- Git fast-forward VS no fast-forward merge
- git fatal Could not read from remote repository
- git fatal I don't handle protocol 'http
- Git fatal Pathspec is in submodule
- Git fatal protocol 'https' is not supported
- Git fatal Reference has invalid format 'refs/heads/master
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.