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?
If the branch contains unmerged changes, though, Git will refuse to delete it. If you're sure you want to do it, you'll have to force the deletion by replacing the -d parameter with an uppercase D: It's like you're pushing—sending—the order to delete the branch to the remote repository.
Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet.
It is safe to delete your local branch after you pushed your changes to your own remote repository. The pull request is unrelated to this, because it is simply a request to the maintainers of the original repository to merge your changes back into their code base.
The command to delete a local git branch can take one of two forms: git branch –delete old-branch. git branch -d old-branch.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With