Fixing Git’s “not fully merged” Error When Deleting a Branch
When git branch -d fails with error: the branch '…' is not fully merged., the branch has commits that are not in the target branch. Git checks whether a branch is merged against its upstream (the remote branch it tracks) if it has one, and against the current branch (HEAD) if it does not. Either merge the commits into that target, switch to a branch that matches the comparison, or confirm that you don't need the commits and delete the branch with -D. Any of these clears the error.
When you clean up a finished branch, it sometimes won't delete even though you think you merged it. In my test environment, this error appeared in three cases: when I was on a different branch, when I had merged with squash or cherry-pick, and when I had commits that were not pushed. For each case I tried a fix and confirmed that the branch could be deleted. (When all the commits had already been brought in, I deleted the branch with -D.)
The test environment was Ubuntu 24.04, Git 2.43.0, and bash 5.2. I ran the commands with LANG=C so the messages would be in English. The remote was a local bare repository created in the same environment and registered with the relative path ../remote.git. I did not test merges made on the pull request screen of GitHub or similar services (such as Squash and merge).
The error message and what it checks
While on main, I tried to delete feature/search with -d, which had not been merged yet. It stopped with the following message. The exit code was 1, and the branch was not deleted.
$ git branch -d feature/search
error: the branch 'feature/search' is not fully merged.
If you are sure you want to delete it, run 'git branch -D feature/search'
According to the official git branch reference, -d deletes only a branch that is fully merged into its upstream branch (or into HEAD if there is no upstream). The -D in the second line is the short form of --delete --force, which deletes the branch whether or not it is merged.
Before using -D, check what has not been merged. git branch --no-merged lists branches that cannot be reached from HEAD. git log main..feature/search shows which commits remain. As described in the official gitrevisions reference on the .. range syntax, main..feature/search means "commits reachable from feature/search but not from main."
$ git branch --no-merged
feature/search
$ git log --oneline main..feature/search
8c77b14 検索の不具合を直す
073ffc8 検索を追加
If you need these two commits, merge them first and then delete the branch. After the merge, -d worked.
$ git merge -q --no-edit feature/search
$ git branch -d feature/search
Deleted branch feature/search (was 8c77b14).
So far, I had simply not merged the branch. The following three sections cover cases where the branch seems merged but still fails.
Already merged into main, but it fails while you are on another branch
I merged feature/footer into main, then tried to delete it while still on another branch, feature/header. Neither branch has an upstream. The same error appeared.
$ git branch --show-current
feature/header
$ git branch -d feature/footer
error: the branch 'feature/footer' is not fully merged.
If you are sure you want to delete it, run 'git branch -D feature/footer'
Since there is no upstream, Git compares against HEAD, which is feature/header here. feature/header was created from main before feature/footer was merged, so it does not contain the "Add footer" commit.

From main, feature/footer is merged. Passing a branch name to git branch --merged lists the branches that are reachable from it.
$ git branch --merged main
feature/footer
main
The fix is to switch to main and then delete the branch. The same -d worked.
$ git switch -q main
$ git branch -d feature/footer
Deleted branch feature/footer (was 11bf00c).
Brought in with squash merge or cherry-pick
As the official git merge reference explains for --squash, git merge --squash stages the branch's changes in the working tree and index all at once. A later git commit records them as one new commit. The content reaches main, but the original branch's commits do not appear in main's history. As a result, -d fails.
I squash-merged feature/menu, which has two commits, and then tried to delete it with -d.
$ git merge --squash feature/menu
Updating 11bf00c..416f27f
Fast-forward
Squash commit -- not updating HEAD
menu.txt | 2 ++
1 file changed, 2 insertions(+)
create mode 100644 menu.txt
$ git commit -q -m "メニューを追加 (squash)"
$ git branch -d feature/menu
error: the branch 'feature/menu' is not fully merged.
If you are sure you want to delete it, run 'git branch -D feature/menu'
$ git log --oneline main..feature/menu
416f27f メニューの色を変える
d9bbe7c メニューを追加
git log makes it look as if neither commit is in main. To check whether the content has been brought in, compare the file differences instead. In this test I did not advance main after the squash merge, so git diff --stat main feature/menu printed nothing, meaning the files on the two branches were identical.
$ git diff --stat main feature/menu
$ git branch -D feature/menu
Deleted branch feature/menu (was 416f27f).
According to the official reference, git cherry checks, commit by commit, whether the other branch has a commit with the same change. Commits that have an equivalent are marked -, and commits without one are marked +. It is useful for finding commits that were brought in by cherry-pick or rebase. When I ran it on the squash-merged feature/menu, both commits were marked +. The two commits had been combined into one, so no commit with the same diff exists in main.
$ git cherry -v main feature/menu
+ d9bbe7c92bc5781a131e26ef99e26ba1a447565b メニューを追加
+ 416f27f4ce6dece0785f0246bb5d1430f5621ac7 メニューの色を変える
In contrast, for feature/logo, where I brought one commit into main with git cherry-pick, the commit was marked -. Even so, main received a new commit with a different hash, so -d still fails. If every line from git cherry is -, the changes have been brought in, and you can delete the branch with -D.
$ git cherry-pick feature/logo
[main 1fa9581] ロゴを追加
Date: Tue Nov 24 10:00:00 2026 +0900
1 file changed, 1 insertion(+)
create mode 100644 logo.txt
$ git branch -d feature/logo
error: the branch 'feature/logo' is not fully merged.
If you are sure you want to delete it, run 'git branch -D feature/logo'
$ git cherry -v main feature/logo
- 748bde1ab265619e847ce514736890b3f058cd64 ロゴを追加
$ git branch -D feature/logo
Deleted branch feature/logo (was 748bde1).
Fails when there are unpushed commits
When a branch has an upstream, Git compares against the upstream instead of HEAD. I pushed feature/cart, added one more commit, merged the branch into main, and then tried to delete it. In git branch -vv, ahead 1 means the branch is one commit ahead of its upstream, origin/feature/cart.
$ git branch -vv
feature/cart c57b116 [origin/feature/cart: ahead 1] カートの件数を直す
* main c57b116 [origin/main] カートの件数を直す
$ git branch -d feature/cart
warning: not deleting branch 'feature/cart' that is not yet merged to
'refs/remotes/origin/feature/cart', even though it is merged to HEAD
error: the branch 'feature/cart' is not fully merged.
If you are sure you want to delete it, run 'git branch -D feature/cart'
A warning appears before the error. It means that the branch is merged into HEAD but not into refs/remotes/origin/feature/cart (the upstream), so Git will not delete it. To see which commits are not in the upstream, use git log.
$ git log --oneline origin/feature/cart..feature/cart
c57b116 カートの件数を直す
I pushed this commit to bring the upstream up to date, and then -d worked.
$ git push origin feature/cart
To ../remote.git
b45c999..c57b116 feature/cart -> feature/cart
$ git branch -d feature/cart
Deleted branch feature/cart (was c57b116).
If you only want to delete the local branch, you can also use -D without pushing. In this case the last commit is already in main, and the remote feature/cart remains.
-D deletes the branch even if it has commits that are not merged. According to the official reference, the branch's reflog is deleted with it. Before deleting, run git log main..<branch-name> to confirm that the remaining commits are really not needed.
If you deleted a branch with -D by mistake, you can recreate it from the reflog
A branch deleted with -D can be recreated from the hash shown after was in the message. If you lose the hash, check git reflog. Deleting a branch removes its reflog, but git reflog (which, according to the official reference, shows the HEAD log when given no arguments) still recorded the HEAD movements from when I committed on that branch.
$ git branch -D feature/tmp
Deleted branch feature/tmp (was 4f02585).
$ git reflog -3
c57b116 HEAD@{0}: checkout: moving from feature/tmp to main
4f02585 HEAD@{1}: commit: 試しの変更
c57b116 HEAD@{2}: checkout: moving from main to feature/tmp
$ git branch feature/tmp 4f02585
$ git log --oneline -1 feature/tmp
4f02585 試しの変更
When you see "not fully merged," first check what Git is comparing against. If there is an upstream, look at git log <upstream>..<branch>. If not, look at git log HEAD..<branch>. Once you know which commits remain, the fix is clear: switch to main if you are on a different branch, push if the commits are unpushed, or use -D if the changes were already brought in by squash merge or cherry-pick.





