There are a couple of things going on here. Firstly, in your desired result, you cannot have two HEAD
s. There is always only one HEAD
.
You get a detached head state when your current head commit is not referenced by any branch name or tag.
Now, regarding why commits are getting placed on top of master
instead of 5.0
. Each commit references a parent commit. i.e. every single commit has a parent which is referenced by its hash. When you fetch changes, the fetched commits also come with their parent references and are placed accordingly. For ex, suppose the following is the state of your remote repo:
A -> B -> C
(C being the latest commit)
And you have the following history in your local:
A -> B
Now no matter what branch you pull or fetch from, when commit C
gets fetched, it will look for commit B
set camp there.
Meaning, it doesn't matter where you call fetch from. A particular commit will reside over same parent on which it was made in the first place.
If you still need to move those 3 commits, I suggest you look into rebase
. Although rebasing public commits will most certainly bite you unless you are the sole contributor to repo.