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
0 answers

detached HEAD warning after git rebase

My history was P --> A --> revert_A --> B I decided to drop revert_A and squash A and B to have P --> A_squash_B I run git rebase -i, drop revert_A, squash B. The history becomes what I wanted, but with this message $ git rebase -i [detached HEAD…
AlexTP
  • 213
  • 1
  • 3
  • 6
0
votes
1 answer

Why am I getting a detached HEAD during gitlab/git merge-request/merge?

Firstly like to mention that I have tried a few things from prior questions but none of them fit my scenario. This does not somehow "register" as a merge in gitlab. I concluded this because when I try to delete the branch after merge, git threw a…
hyperbolicme
  • 29
  • 1
  • 8
0
votes
1 answer

Recover git detached head commit

I pushed changes to a branch with a detached head using IntelliJ. It gave me an obscure warning but accepted my push without forcing. Then I checked out the branch and all my changes disappeared. Where are they and how do I get them back?
Alex Worden
  • 3,374
  • 6
  • 34
  • 34
0
votes
1 answer

Why is my GIT Submodule *NOT* a detached head?

Basically the opposite of this question. I'm cloning a repo that has a submodule in it. After running git submodule init git submodule update when I cd to the subdirectory that contains the submodule, I expect to see that I am in a detached HEAD…
Murkantilism
  • 1,060
  • 1
  • 16
  • 31
0
votes
1 answer

Push changes based on previous commit?

GitLog I checked out the commit right before my most recent commit, made some changes, and now I want to overwrite/merge the code I currently have (edited version of "Refined zoom...") with the most recent commit ("Added call API..."). However,…
Perry
  • 35
  • 1
  • 8
0
votes
1 answer

How do I reliably get a value for HEAD that I can checkout again?

My Git repository is in a state where HEAD might be a branch, or it might be a detached head. In a script, I want to get the current value such that I can reliably restore it with git checkout later: that is, if we're on a branch now, I want to come…
Dan Hulme
  • 14,779
  • 3
  • 46
  • 95
0
votes
1 answer

Why is it always a detached HEAD?

I have a git repo with two remote. origin/master cm/master | | | | sfcc--------------cm/sfcc-18 | | feature The above is the basic structure of my repo.…
Vini
  • 1,978
  • 8
  • 40
  • 82
0
votes
2 answers

GIT checkout tag issues - detached HEAD state

The purpose of this project is to call code not in the standard UNIX path. My professor has provided steps to clone gawk from a GIT repository and then build and install in an autoconf format. MY PROBLEM IS - After cloning from…
Joe
  • 3
  • 3
0
votes
1 answer

Git- Resolve Detached HEAD on server

I am fairly new to Git- having only been using it since I started working for my current employer. I recently pushed some changes to the server, having merged a bug fix implemented by a colleague on my local development machine. I did this by…
Noble-Surfer
  • 3,052
  • 11
  • 73
  • 118
0
votes
1 answer

How can I force branch version on local master?

I had to reset detached head to previous commit. Both master and branch say no local changes to save. Only my local branch works, the local-master does not! How do I make sure the branch version gits to my origin?
bperlik
  • 23
  • 1
  • 5
0
votes
1 answer

Is it possible to see detached head state in IntelliJ?

Is it possible to see detached head state in IntelliJ? IntelliJ swears it can't operate on Git due to detached head, but no any sign of this state is visible in log. The only sign is that hexadecimal branch is displayed in the lower right corner. Is…
Dims
  • 47,675
  • 117
  • 331
  • 600
0
votes
1 answer

Detached head does not disappear by creating branch. Why?

I am always falling into detached head state I don't know why. And still not able to find a good way to get out of it. Some time I was thinking that it is sufficient to create branch when in detached head, but this doesn't help, HEAD remains…
Dims
  • 47,675
  • 117
  • 331
  • 600
0
votes
2 answers

Git merge branch from detached

I have sample where git merge gives unexpected for me result. Here master branch has commit #3 with unwanted changes. I checkouts to stable commit #2 and creates new branch with additional usage. Can I merge new_branch into master with all three…
Dmitry
  • 31
  • 5
0
votes
0 answers

Git Detached Head

I have run into this Git detached head and haven't found a solution yet that has worked. Here is my scenario... I have a Dev branch I work on, committed several times and then all of the sudden notice I have a "detached head" and my Dev branch is…
mgrenier
  • 1,409
  • 3
  • 21
  • 45
0
votes
1 answer

Is there a table somewhere underlining the difference between these git commands?

It seems there is some overlap in those git sub-commands: describe rev-parse name-rev symbolic-ref show-ref Is there a nice table somewhere which underlines what some of them can not do? It should cover: failure…
Robert Siemer
  • 32,405
  • 11
  • 84
  • 94