git branch -d gives warning
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 toHEAD
.
Solution 1:
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:
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:
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:
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:
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:
-
myfeature
==>origin/myfeature
(myfeature
has been pushed up to remote repo) - then
myfeature
is deleted - 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.