I ended up with a detached head today, the same problem as described in: git push says everything up-to-date even though I have local changes
As far as I know I didn
Detached HEAD
means that what's currently checked out is not a local branch.
Some scenarios that will result in a Detached HEAD
state:
If you checkout a remote branch, say origin/master
. This is a read-only branch. Thus, when creating a commit from origin/master
it will be free-floating, i.e. not connected to any branch.
If you checkout a specific tag or commit. When doing a new commit from here, it will again be free-floating, i.e. not connected to any branch. Note that when a branch is checked out, new commits always gets automatically placed at the tip.
When you want to go back and checkout a specific commit or tag to start working from there, you could create a new branch originating from that commit and switch to it by git checkout -b new_branch_name
. This will prevent the Detached HEAD
state as you now have a branch checked out and not a commit.