Questions tagged [git-detached-head]

Use this tag for questions about a Git repository in "detached HEAD" mode. A repository is in this mode if `git status` says "HEAD detached at ..." or "HEAD detached from ..."

In a repository, a detached HEAD is a mode where HEAD contains a raw commit hash ID. This mode or state is perhaps best defined by contrasting it to the more typical attached HEAD state. When a repository's HEAD is attached, the special file .git/HEAD contains the name of the current branch. This results from running git checkout branch-name, which puts you on the branch named branch-name. That is, your HEAD is normally attached to some branch, so that Git knows which branch you're on. But Git's HEAD is easily detached from this branch, so that it can move to another branch, or even directly to a commit.

When in this detached HEAD mode, Git will tell you that you are not on any branch. For instance, running git branch may print:

* (HEAD detached at 3e5524907)
  master

and git status will say HEAD detached ..., rather than on branch ... (see ).

A detached HEAD is not an error state, but it is also not a typical mode in which one does work in the repository. You will most commonly see it in one of these situations:

  • during a paused interactive rebase (see ), when you choose to edit some commit(s);
  • during any rebase that pauses due to conflicts;
  • during normal operation of most submodules (see ).

You will also end up in "detached HEAD" state by checking out any commit using any name that is not itself a branch name. For instance, git checkout origin/master will often check out the same commit as git checkout master, but since origin/master is a remote-tracking name rather than a branch name, you will be in this "detached HEAD" state.

The simplest way to recover, if you are in this state unexpectedly—e.g., do not have a rebase to continue (if you are uncertain, use git status to find out)—is just to check out a branch by name, e.g., git checkout master. If you have made new commits in this state, however, consider creating a branch name to record them.

96 questions
0
votes
3 answers

Git Detached HEAD lost data

Somehow, I ended up with a detached HEAD. I made some commits and they showed up in my commit history as HEAD (but master was several commits behind). Then I tried to fix the detached head by checking out master. Now I don't see my previous commits…
Jeff
  • 35,755
  • 15
  • 108
  • 220
0
votes
1 answer

Detached Head in GitHub

Can someone help me? I tried to sync to a branch of my GitHub project when it told me that I had a detached head. How do I fix it? Here's a screenshot: Thanks a lot!
-1
votes
1 answer

Detached head state in closed development environment

A similar question has been asked already, however it does not provide the solution for my situation. My origin/develop branch is in a closed environment (azure devops) and can only be changed via a pull request. Also it is in detached head state.…
Eeuwigestudent1
  • 161
  • 1
  • 2
  • 13
-1
votes
1 answer

After pulling from git, submodules are in detached head state

I am running git on windows 8.1, and pulling from upstream using the following batch script: git pull --recurse-submodules git submodule update --recursive --remote --init --merge git submodule foreach "git pull || true" I know that it is…
Alex O
  • 1,429
  • 2
  • 13
  • 20
-1
votes
1 answer

Deleted my project by reset HARD or clear - github-mac

Im soo gaddem stupid, I need some help here. I was trying to get my project to Github and i created a repo in github. Then i did git clone ........git and after a few tryes, my project was gone. I had some problems doign "git add ..." becouse…
Sindri Þór
  • 2,887
  • 3
  • 26
  • 32
-2
votes
2 answers

How to find a bug in origin with git tools

I develop my app locally (in my own branch), but I can only test it on a remote dev server, by pushing to a git repo (my own branch) on the server, and then testing a working copy there. As I can't find out why my web app crashed, I want to find the…
Konst54
  • 175
  • 9
1 2 3 4 5 6
7