git branch -d gives warning

Git

Git Problem Overview


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.

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

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.

Solution 3 - Git

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).

Solution 4 - Git

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

Solution 5 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1322228View Question on Stackoverflow
Solution 1 - GitcjhvealView Answer on Stackoverflow
Solution 2 - GitKarl BielefeldtView Answer on Stackoverflow
Solution 3 - GitMax KomarychevView Answer on Stackoverflow
Solution 4 - GitMithun NairView Answer on Stackoverflow
Solution 5 - GitMike WilliamsonView Answer on Stackoverflow