151

Just want to get a better understanding of the warning message after I deleted a local branch

warning: deleting branch 'old_branch' that has been merged to 'refs/remotes/origin/old_branch', but not yet merged to HEAD.

3
  • 75
    if you merge --squash your old_branch you'll get this warning always when deleting it locally. When squashing your index is reset hence does not match old_branch HEAd Commented Jul 3, 2015 at 9:07
  • 3
    While the other answers are correct, Antoine's comment was the reason at least in my case.
    – Squrppi
    Commented Mar 5, 2020 at 11:09
  • 4
    @AntoineWils, this should an answer.
    – 0TTT0
    Commented Sep 17, 2022 at 17:53

6 Answers 6

109

This is just warning you that you have changes pushed to the branch on origin, but they are not merged into the currently checked out branch, so you are only deleting it locally.

It is warning you that you no longer have a local copy of that branch, but it exists in origin

If you want to delete the remote branch as well, use git push --delete origin old_branch

4
  • 11
    Yeah, master is not involved in this. You mean the current branch, rather. ;) Commented Aug 31, 2016 at 18:43
  • 3
    I get this warning even if I do a git branch -d branch_name which is supposed to only delete the branch locally. Why is the warning needed in this case? Commented Nov 15, 2017 at 8:55
  • 4
    But origin/old_branch is merged into origin/master. Later I did git pull origin on master branch. Still same error. Isn't this bug in GH ?
    – vikramvi
    Commented Mar 8, 2018 at 11:06
  • I'm getting: error: failed to push some refs to 'github.com/repo/repo.git'
    – 629060311
    Commented Mar 31, 2022 at 21:10
46

Assuming you currently have master checked out, it means the changes made in old_branch aren't present in master. However, they are present in old_branch on origin.

3
  • 8
    Yep. This is the correct answer! "but not yet merged to HEAD", the HEAD here reference the local master branch's HEAD.
    – Devy
    Commented Sep 10, 2015 at 22:09
  • 7
    But origin/old_branch is merged into origin/master. Later I did git pull origin on master branch. Still same error. Isn't this bug in GH ?
    – vikramvi
    Commented Mar 8, 2018 at 11:07
  • 5
    @vikramvi Assuming you have master checked out locally, it can still occur if the SHA of any of the commits has changed; i.e. you rebased origin/old_branch onto origin/master. Even if it was a fast-forward, this will generate a new SHA for each new commit from origin/old_branch, causing git to see the original SHA's in your local old_branch as unmerged after pulling the changes to your local master branch. You can see this answer and this answer for why this occurs.
    – user711807
    Commented Jul 30, 2018 at 0:09
11

This means your local branch old_branch is up to date with remote branch old_branch on remote origin but it is not merged to the branch master which is considered to be the main branch in the repo.

It is just a precaution from git. It gives you a hint: maybe you did your job in the topic-branch and forget to merge it to the main branch?


update

Git warns you from losing your changes. For example if you do not have your old_branch on the master git then don't allow you to even delete branch that is unmerged to the master (well it allow, but with key -D which is force-delete option).

2
  • 9
    Not necessarily master, but the current HEAD. Commented Apr 10, 2015 at 4:20
  • So the -D is when you have not shared the branch being deleted (really it's commits) with any remote branch. While the warning is to inform you that you have shared the branch (commits) with the remote but it just is not merged into HEAD. HEAD is HEAD, remote/refs/HEAD is not the same. But please correct me if I am wrong regarding the differences between remote HEAD and local HEAD.
    – Eric
    Commented Jan 5, 2017 at 15:32
9

To add to the other answers, this can also mean that the change might be merged to master, just that your local copy of master does not reflect it yet. Either ways this just informs you that the local copy of your master does not have the changes you pushed on origin. Merged/Not merged...maybe,maybe not

7

Several answers here are completely correct, but seem to have not fully cleared up the question. So I will try another attempt.

OP Question Paraphrased

After I perform a Pull Request and remove a branch on GitHub/Bitbucket/etc. automatically via completing the PR, I am then seeing this error when deleting the branch locally: warning: deleting branch 'old_branch' that has been merged to 'refs/remotes/origin/old_branch', but not yet merged to HEAD.

Understanding Timeline

GitHub, or whatever remote repository, has no knowledge of the local state of your machine.

When a pull request is completed and it offers to remove the original PR branch, it has no knowledge of your local branch.

At this point, you delete your local branch. Your local repo/computer knows this timeline:

  1. myfeature ==> origin/myfeature (myfeature has been pushed up to remote repo)
  2. then myfeature is deleted
  3. So origin/myfeature still exists even though it has no local representation

Of course, this is not true, because the origin/myfeature branch was destroyed when the PR was completed, but your local computer does not know this. So, Git gives you the warning.

Shouldn't GitHub/BitBucket/etc. Make This Easier?

Because the

PR Complete ==> Remote Branch Removed

paradigm is so common, it would be nice if maybe the remote branch somehow informed the local branch of this occurrence. But Git has done remarkably well with "one-directional communication" where you only request information but never send unrequested information. "Bi-directional" communication in one area would likely make people want it in other areas, too, and soon we're back to Git looking more like SVN or any of the other "central repository" paradigms that were too brittle to succeed. Someone who knows more than me can probably elaborate better all the problems this "two-way communication" would cause.

1
  • 2
    A further note: it might be worth reading up on git prune, as it is a simple way to clear up any "extra junk" when you have pointers to remote branches that no longer work. Commented Mar 9, 2021 at 19:22
0

this means you changes for this branch is merged in remote(main/master) but not in local(main/master).

to avoid theses warning, must take checkout to main/master and then take pull.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.