Matt Fenwick Matt Fenwick - 1 month ago 9
Git Question

Why doesn't git allow me to safely delete a branch?

I needed to merge two branches --

second
into
first
and then get rid of
second
. 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
second
branch?

Answer

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.