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
.
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
.
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
master
is not involved in this. You mean the current branch, rather. ;)
Commented
Aug 31, 2016 at 18:43
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
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
.
HEAD
", the HEAD
here reference the local master branch's HEAD.
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.
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).
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
Several answers here are completely correct, but seem to have not fully cleared up the question. So I will try another attempt.
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.
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)myfeature
is deletedorigin/myfeature
still exists even though it has no local representationOf 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.
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.
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
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.