* [971f835] (HEAD, original_idea) Now working here. Some comment 9 * [692b673] Some comment 8 * [3ebff62] Reverted to original idea. Some comment 7 | * [72ea01d] (master) Decided it wasn't worth the effort. Some comment 6 | * [985c1ad] Some comment 5 | * [4d7d491] Some comment 4 | * [0c697bb] Branched to try an idea. Some comment 3 |/ * [7280b1f] Some comment 2 * [5c2c6d0] Some comment 1 * [bc7aac6] Initial commit
So, master
got left behind. Not sure how that happened. Once I decided I was done with the branch that didn't work out I checked out [7280b1f]
and continued from there.
How do I fix this? I this the infamous "detached head" issue?
Does master
have to be aligned with HEAD
for optimal health of the repo?
My workflow is super-simple. This is just managing a single text file. In the vast majority of cases it's:
git add . git commit -am "Some comment"
And that's it.
I decided to try an idea and created a branch. When it didn't work out I checked out the root of that branch and went back to the git add/commit
routine.
For those who may not know, the 'master' branch was the default branch name for any git's fresh repository. Therefore, many people often used it as a stable branch. Spurred by the rise in racism cases across the US, GitHub recently renamed its 'master' branch to 'main'. the company said.
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:
original_idea
on your schema)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'
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