4

git branch -d is almost always wrong about if a branch has code I haven't merged. Very often I'll have branched foo off of master, done work, and then merged it back into master, but then git branch -d says "The branch 'foo' is not fully merged", until I merge master back into foo (which is sometimes a pain).

John Bachir
  • 22,495
  • 29
  • 154
  • 227
  • 1
    once you have merged a branch you should not receive this message. git checks if all commits of branch foo are reachable from branch master. it only complains if there are new (unmerged) commits in foo. what version of git are you using? can you post a simple testcase to reproduce this behavior? – knittl Feb 14 '11 at 21:00

4 Answers4

4

You should not have to merge something into foo to be able to delete foo.

As far as I experienced, the criterion is whether foo is merged into HEAD, so maybe you should make sure master is your current branch when trying to delete foo.

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
  • Yes, I am certain of that. It's possible that the branch i question was merged into a **bar**, which was then merged into **master**… I figured git should be smart enough to see that those changesets exist in master. – John Bachir Feb 14 '11 at 22:48
  • Hmm actually in this case it looks like i squashed **foo**'s commits, so they had different refs. But I'm pretty certain the scenario I've described above has happened. – John Bachir Feb 14 '11 at 22:50
  • Look with `gitk` or `git log` or something, whether the tip of **foo** is reachable from your current head. – Paŭlo Ebermann Feb 14 '11 at 23:02
1

in this case it looks like i squashed foo's commits

That would be consistent with the "isn't fully merged" warning (branch with commits that are not reachable from any other ref head)

Two checks can be done:

1/ The "Git and “The branch 'x' is not fully merged” Error" question is interesting:

git log --graph --left-right --cherry-pick --oneline master...foo

2/ See "Using Git, show all commits that are in one branch, but not the other(s)"

git branch --contains branch-to-delete

More than one branch should be returned

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

Do a

git rebase master foo

after you have merged everything. Then a git branch -d foo should succeed

schoetbi
  • 12,009
  • 10
  • 54
  • 72
-5
#!/bin/sh
# Get rid of all the branches I don't care about.

for b in $(git branch) ; do
  git rebase master ${b}
  if test $? -ne 0; then git rebase --abort ; fi
  git checkout -f master
done

for b in $(git branch) ; do git branch -d ${b} ; done
Cascabel
  • 479,068
  • 72
  • 370
  • 318