How to move master to HEAD?
If git branch
shows that your current branch is original_idea, that wouldn't be a detached HEAD situation.
But in any case, if you want your master to reflect your "current commit" (which is what HEAD means in Git):
git branch -f master HEAD
git checkout master
You would find other alternatives in "How to I “move” my commits from “no branch” to an actual branch?".
The problem with this is that it makes the entire branch currently ending at master disappear.
Then all you need to do is:
- make sure HEAD is referenced by a branch (like
original_idea
on your schema) - rebase that branch on top of master:
That would mean:
git checkout original_idea
git rebase master
git checkout master
git merge original_idea
Is this the infamous "detached head" issue?
No, HEAD is pointing at branch original_idea
Does master have to be aligned with HEAD for optimal health of the repo?
No, master is just a conventional name, usually taken to be a branch which is readily buildable and hopefully a working snapshot.
How do I fix this?
If you have pushed master to another repository, you need to merge you changes from original_idea into master:
git checkout master
git merge original_idea
Be aware that if there are any conflicting changes you'll need to resolve them.
If you have not yet pushed master to another repository, you could delete master and recreate it from original_idea. WARNING: Everyone who was working on master will have to reset their master branch.
$ git checkout master
Switched to branch 'master'
$ git checkout -b experiment_1
Switched to a new branch 'experiment_1'
# Here we are going to delete master. Should be safe, since experiment_1
# was created from this point on the previous command
$ git branch -d master
Deleted branch master (was 72ea01d).
$ git checkout original_idea
Switched to branch 'original_idea'
# Now that we checked out the branch HEAD is pointing to, we can recreate master
$ git checkout -b master
Switched to a new branch 'master'