Here are the commands I used from the master branch
git branch experiment
git checkout experiment
Then I made some changes to my files, committed the changes, and pushed the new branch to GitHub.
git commit . -m 'changed files'
git push -u origin experiment
Later on I decided to merge my experiment branch into the master branch.
git checkout master
git merge experiment
Finally I pushed the changes to GitHub.
git push -u origin master
All went well until I tried deleting my experiment branch using
git branch -d experiment
I got the error message:
error: The branch ‘experiment’ is not fully merged.
If you are sure you want to delete it, run ‘git branch -D experiment’.
I’m a bit new to git, and I don’t know how much more I could possibly merge the two branches. What am I missing here?
Note Wording changed in response to the commments. Thanks @slekse
That is not an error, it is a warning. It means the branch you are about to delete contains commits that are not reachable from any of: its upstream branch, or HEAD (currently checked out revision). In other words, when you might lose commits¹.
In practice it means that you probably amended, rebased (including squash merge) or filtered commits and they don’t seem identical.
Therefore you could avoid the warning by checking out a branch that does contain the commits that you’re about un-reference by deleting that other branch.²
You will want to verify that you in fact aren’t missing any vital commits:
This will give you a list of any nonshared between the branches. In case you are curious, there might be a difference without
--cherry-pickand this difference could well be the reason for the warning you get:¹ they’re really only garbage collected after a while, by default. Also, the
git-branchcommand does not check the revision tree of all branches. The warning is there to avoid obvious mistakes.² (My preference here is to just force the deletion instead, but you might want to have the extra reassurance).