Git is warning that you might lose history by deleting this branch. Even though it would not actually delete any commits right away, some or all of the commits on the branch would become unreachable if they are not part of some other branch as well.
For the branch experiment
to be “fully merged” into another branch, its tip commit must be an ancestor of the other branch’s tip, making the commits in experiment
a subset of the other branch. This makes it safe to delete experiment
, since all its commits will remain part of the repository history via the other branch. It must be “fully” merged, because it may have been merged several times already, but now have commits added since the last merge that are not contained in the other branch.
Git doesn’t check every other branch in the repository, though; just two:
- The current branch (HEAD)
- The upstream branch, if there is one
The “upstream branch” for experiment
, as in your case, is probably origin/experiment
. If experiment
is fully merged in the current branch, then Git deletes it with no complaint. If it is not, but it is fully merged in its upstream branch, then Git proceeds with a warning seeming like:
warning: deleting branch 'experiment' that has been merged
to 'refs/remotes/origin/experiment', but not yet merged to
HEAD.
Deleted branch experiment (was xxxxxxxx).
Where xxxxxxxx
indicates a commit id. Being fully merged in its upstream indicates that the commits in experiment
have been pushed to the origin repository, so that even if you lose them here, they may at least be saved elsewhere.
Since Git doesn’t check other branches, it may be safe to delete a branch because you know it is fully merged into another one; you can do this with the -D
option as indicated, or switch to that branch first and let Git confirm the fully merged status for you.
git commit --amend
squash
: stackoverflow.com/q/41946475/109941