git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: could not detach HEAD error didn't identify the cause of the issue

From
Jeff King <peff@peff.net>
Date
Sep 14, 2009, 11:22 UTC
Message-ID
<20090914112211.GC9216@sigill.intra.peff.net>
In-Reply-To
<4AAD8AE0.9070305@catalyst.net.nz>
On Mon, Sep 14, 2009 at 12:14:24PM +1200, Ben Bradshaw wrote:
Show 11 quoted lines
> I was asked to post this issue to the list, I've just had git tell me it
> can't detach HEAD which left me scratching mine as to the cause and fix.
> Turns out if I have local untracked files that the remote branch also
> has then this error will trigger. I have included my shell backlog
> (client data removed). In this example the site_map folder was present
> on master and I had a local, untracked copy.
> 
> git can obviosly detect this issue and stop my local copy getting in a
> bad state, but an error message such as "sites/all/modules/site_map/ is
> present in HEAD but is untracked locally, unable to apply changes" (or
> something to point the finger) would be much appreciated.
I couldn't reproduce it here; I get such a message.
  # set up forked repo, "another" exists only on master
  $ mkdir repo && cd repo
  $ git init
  $ echo content >file && git add file && git commit -m base
  $ echo content >another && git add another && git commit -m another
  $ git checkout -b other HEAD^
  $ echo changes >file && git commit -a -m changes
  # add untracked "another" here
  $ echo untracked >another
  # try rebase
  $ git rebase master
  First, rewinding head to replay your work on top of it...
  error: Untracked working tree file 'another' would be overwritten by merge.
  could not detach HEAD
  # try git pull --rebase, in case it hides the message
  $ git config branch.other.remote .
  $ git config branch.other.merge refs/heads/master
  $ git pull --rebase
  From .
   * branch            master     -> FETCH_HEAD
  First, rewinding head to replay your work on top of it...
  error: Untracked working tree file 'another' would be overwritten by merge.
  could not detach HEAD
I'll admit the "could not detach HEAD" message would probably be better as:
  rebase: unable to move HEAD to 'master', aborting rebase
or something similar.

What version of git are you using? What does my test case above produce for you?

-Peff
Previous: Ben BradshawNext: Ben Bradshaw
Message 2 of 4 in “could not detach HEAD error didn't identify the cause of the issue”
  1. Ben BradshawSep 14, 2009
  2. Jeff KingSep 14, 2009
  3. Ben BradshawSep 14, 2009
  4. Jeff KingSep 14, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.