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?
There are times when you get an “not fully merged” error for a git branch, usually when trying to delete a local branch from your machine. It's a safe bet that something in your local branch has not actually made it to the remote repository and we should do some investigating.
You can undo a Git merge using the git reset –merge command. This command changes all files that are different between your current repository and a particular commit. There is no “git undo merge” command but the git reset command works well to undo a merge.
Deleting a branch LOCALLY Delete a branch with git branch -d <branch> . The -d option will delete the branch only if it has already been pushed and merged with the remote branch. Use -D instead if you want to force the branch to be deleted, even if it hasn't been pushed or merged yet.
The more the branches and master diverge away from each other the farther away their “common ancestor” commit becomes. When you're done with a branch and it has been merged into master, delete it. A new branch can be made off of the most recent commit on the master branch.
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 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:
git log --graph --left-right --cherry-pick --oneline master...experiment
This will give you a list of any nonshared between the branches. In case you are curious, there might be a difference without --cherry-pick
and this difference could well be the reason for the warning you get:
--cherry-pick
Omit any commit that introduces the same change as another commit on the "other side" when the set of commits are limited with symmetric difference. For example, if you have two branches, A and B, a usual way to list all commits on only one side of them is with --left-right, like the example above in the description of that option. It however shows the commits that were cherry-picked from the other branch (for example, "3rd on b" may be cherry-picked from branch A). With this option, such pairs of commits are excluded from the output.
¹ they're really only garbage collected after a while, by default. Also, the git-branch
command 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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With