Matt Fenwick Matt Fenwick - 1 year ago 74
Git Question

Why doesn't git allow me to safely delete a branch which has been merged into HEAD?

I needed to merge two branches --

and then get rid of
. Here's what I did:

  • git clone
    d the project to get a fresh copy

  • git checkout --track origin/second
    , made some changes, and committed

  • git checkout --track origin/first
    , made some changes, and committed

  • git merge second
    (git says "merge made by recursive")

  • git branch -d second

Then git says:

$ git branch -d second
warning: not deleting branch 'second' that is not yet merged to
'refs/remotes/origin/second', even though it is merged to HEAD.
error: The branch 'second' is not fully merged.
If you are sure you want to delete it, run 'git branch -D second'.

Why is this happening? I've never gotten this message after a merge before. The merge worked just fine, no conflicts. How do I safely delete the

Answer Source

Based on my experiments and @knittl's and @twalberg's comments, it seems that git just wanted me to push my changes to the second branch before deleting it.

I did:

$ git checkout second
$ git push origin second
$ git checkout first
$ git branch -d second

which worked without warnings.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download