git runtime_error ai_generated true

error: The branch 'feature-x' is not fully merged. If you are sure you want to delete it, run 'git branch -D feature-x'.

ID: git/error-branch-not-fully-merged

Also available as: JSON · Markdown · 中文
95%Fix Rate
85%Confidence
1Evidence
2023-04-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
git 1.7.0 active
git 2.30.0 active
git 2.45.0 active

Root Cause

Attempting to delete a branch with git branch -d that has commits not reachable from the current HEAD or its upstream, indicating potential loss of work.

generic

中文

尝试使用 git branch -d 删除一个分支,该分支包含从当前 HEAD 或其上游无法到达的提交,表明可能会丢失工作。

Official Documentation

https://git-scm.com/docs/git-branch#Documentation/git-branch.txt--d

Workarounds

  1. 100% success git branch -D feature-x # Force delete the branch if you are certain its work is no longer needed
    git branch -D feature-x  # Force delete the branch if you are certain its work is no longer needed
  2. 90% success git checkout feature-x && git log --oneline --not --remotes=origin # Review unmerged commits, then merge or cherry-pick them to main before safe deletion with git branch -d
    git checkout feature-x && git log --oneline --not --remotes=origin  # Review unmerged commits, then merge or cherry-pick them to main before safe deletion with git branch -d

中文步骤

  1. git branch -D feature-x  # Force delete the branch if you are certain its work is no longer needed
  2. git checkout feature-x && git log --oneline --not --remotes=origin  # Review unmerged commits, then merge or cherry-pick them to main before safe deletion with git branch -d

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Running git merge --squash on the branch before deleting does not actually merge the commits; it only creates a squash commit that doesn't preserve history, so the branch still appears unmerged.

  2. 50% fail

    Using git branch -d after a git rebase that rewrites history may still fail because the original commits are no longer directly referenced, even if they are functionally merged.