Reputation: 49085
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 copygit checkout --track origin/second
, made some changes, and committedgit checkout --track origin/first
, made some changes, and committedgit 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?
Upvotes: 39
Views: 12203
Reputation: 408
I think this actually happens when you have merged a branch on the remote (i.e. via a Pull Request
) and deleted the remote branch.
In my experiment not deleting the remote branch and using -d
locally FIRST is the solution.
Upvotes: 0
Reputation: 2343
Basically, the local "second" branch is not synced with the remote "second" branch, and git does not want you to lose any work.
In this situation, the update is not sure to get lost because it has already merged to "HEAD". If the "HEAD" branch is pushed to remote, there should not be a problem. However, if there is something wrong with "HEAD", there still is a chance you lose your work
To conclude, it just an extra guarantee, feel free to forcibly delete.
Upvotes: 0
Reputation: 49085
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.
Upvotes: 58