Git
error
branch
merge conflict
software development

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.

Browse interview questions

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:

bash
git log --oneline --left-right --cherry main...feature-x

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:

bash
git log --oneline main -- path/to/file
git cherry -v main feature-x

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.

bash
git checkout main
git merge --no-ff feature-x
git branch -d feature-x

This preserves history and satisfies safe deletion condition.

Option 2: Delete Forcefully When Intentional

If you confirm branch can be discarded, force delete:

bash
git branch -D feature-x

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.

bash
git tag backup/feature-x feature-x
# or
git branch backup-feature-x feature-x

Then delete original branch if still desired.

Recover If Deleted by Mistake

If branch was removed accidentally, recover through reflog.

bash
git reflog
# find old tip hash
git branch restored-feature <hash>

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:

bash
git push origin --delete feature-x

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.

bash
git log --oneline main..feature-x
git diff main...feature-x

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
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track 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.

Browse interview questions

All Rights Reserved.