-1

I have read the similar Question Git error: refname 'HEAD' is ambiguous and tried all the answers but in my case those do not help, since the reason for the message in the usual case is a local branch or tag named HEAD. I found this message to appear even when no HEAD or head branch is within the workspace.

I'm facing the following issue, after each interaction with git I get the warning:

$git status
warning: refname 'HEAD' is ambiguous.
warning: refname 'HEAD' is ambiguous.
warning: refname 'HEAD' is ambiguous.
Auf Branch main
Ihr Branch ist auf demselben Stand wie 'origin/main'.

nichts zu committen, Arbeitsverzeichnis unverändert

No I checked all my local and remote branch and tag names and also did the prune thing:

git fetch --prune

but still, no luck. The message has popped up a few weeks after hosting an other git repo within my parent multi repo but with its own forked head, so this might have somehow trigger the issue. I moved the repo out but the error is still there. Any suggestions?

PS I do not have a branch called head:

git show-ref
84dac8551de99be283025395338935cd9583c707 refs/heads/Resoner-provierder-as-singleton-hook-experiments
4350427f8397f7c12c16c3f38a15a14cddf2061a refs/heads/add-RNTet
f00d5c15743cabf3fe2b41e68b71c0278e9d8e3a refs/heads/bring_OCR_back
a15789e8f93a23f8a6ec5436608a6c1a0001713d refs/heads/local
6818867b2be03fdb3b606a6e910ef5093e5b81c5 refs/heads/locale
20cdee211a6ad0d8346d3bc445ee7073fb0b03fc refs/heads/main
a4cb53d8fccc568b00283d8daa9b55d2b1fce35f refs/heads/refactoring-of-getStatements
ea8d2b94c2b36932dfdc1ccffd9e5d990546e4c5 refs/heads/refactoring-of-getStatements-mergebranch
572750357cfe3f73633f5c7bf4545857ba1c24ea refs/heads/reproducing_the_tesseract_issue_in_the_simulator
84dac8551de99be283025395338935cd9583c707 refs/remotes/origin/Resoner-provierder-as-singleton-hook-experiments
4350427f8397f7c12c16c3f38a15a14cddf2061a refs/remotes/origin/add-RNTet
f00d5c15743cabf3fe2b41e68b71c0278e9d8e3a refs/remotes/origin/bring_OCR_back
6818867b2be03fdb3b606a6e910ef5093e5b81c5 refs/remotes/origin/locale
20cdee211a6ad0d8346d3bc445ee7073fb0b03fc refs/remotes/origin/main
a4cb53d8fccc568b00283d8daa9b55d2b1fce35f refs/remotes/origin/refactoring-of-getStatements
ea8d2b94c2b36932dfdc1ccffd9e5d990546e4c5 refs/remotes/origin/refactoring-of-getStatements-mergebranch
572750357cfe3f73633f5c7bf4545857ba1c24ea refs/remotes/origin/reproducing_the_tesseract_issue_in_the_simulator
22e504f1143c43b38ad058931fae8599f4e09305 refs/stash
61880f86be6a3d6624b32ce2a5dbc75b7a1d4d5c refs/tags/mileston/1

PPS (no HEAD head situation) the .git folder looks good as well:

➜  .git git:(main) ll
total 80
-rw-r--r--    1 mac  staff    51B 19 Feb 23:59 COMMIT_EDITMSG
-rw-r--r--    1 mac  staff    85B 20 Feb 00:07 FETCH_HEAD
-rw-r--r--    1 mac  staff    21B 19 Feb 18:06 HEAD
-rw-r--r--    1 mac  staff    41B 20 Feb 00:07 ORIG_HEAD
-rw-r--r--    1 mac  staff   1,0K 19 Feb 23:57 config
drwxr-xr-x    3 mac  staff    96B 27 Sep 22:16 hooks
-rw-r--r--    1 mac  staff    19K 19 Feb 23:59 index
drwxr-xr-x    4 mac  staff   128B 27 Sep 23:01 logs
drwxr-xr-x  260 mac  staff   8,1K 20 Feb 00:07 objects
drwxr-xr-x    6 mac  staff   192B 20 Feb 16:02 refs
drwxr-xr-x   16 mac  staff   512B 21 Jan 12:19 rr-cache

PPPS (.gitmodules)

➜  fak10 git:(main) find . -name ".gitmodules"
./node_modules/extsprintf/.gitmodules
./node_modules/verror/node_modules/extsprintf/.gitmodules
./packages/app/node_modules/art/.gitmodules
./packages/app/node_modules/art/lib/slick/.gitmodules
./packages/app/node_modules/extsprintf/.gitmodules
./packages/app/node_modules/verror/node_modules/extsprintf/.gitmodules
./packages/app/node_modules/realm/vendor/realm-core/.gitmodules
./packages/app/node_modules/realm/src/object-store/.gitmodules

PPPS (workaround)

Its actually quite easy to get rid of the problem by deleting local copy and cloning the repo once again, but it would be good to get behind the issue in order to batter understand it.

Macilias
  • 3,279
  • 2
  • 31
  • 43
  • Did you doucle-check from where (which dir) you're doing your commands? – Romain Valeri Feb 19 '22 at 23:15
  • sure, from within the repo specifically: parent folder – Macilias Feb 19 '22 at 23:17
  • Odd. If you're outside of your repo and don't get `fatal: not a git repository (or any of the parent directories): .git` then you could be inside another repo? Did you mean the root of the repo? If so, that's not it, forget my suggestion. – Romain Valeri Feb 19 '22 at 23:20
  • well but I'm not and I don't get any other message or warning and everything works, the message is just annoying. – Macilias Feb 19 '22 at 23:22
  • well, than read more closely please, It clearly states: I don't have a branch called HEAD not local and not in origin, when I run: git branch -m HEAD newbranch I get: fatal: Ungültiger Branchname: 'HEAD' Its clearly a different issue – Macilias Feb 20 '22 at 15:00
  • What do you mean by "parent multi repo"? A directory with other git repos? – apflieger Feb 20 '22 at 15:16
  • Sorry, I meant monorepo. All dependencies basically in one big repo and one of those dependencies had its own git head. As I mentioned it was working fine for some time, so I'm not sure if its even the reason for this strange behaviour. – Macilias Feb 20 '22 at 15:34
  • The correct way to say this is not a duplicate is “I’ve read x, here’s me trying _all the answers_ and I still have the same problem” not “I am right, git is wrong and you all need to learn to read” in all caps :). System/tool error messages (almost) always mean exactly what they say, you need to take them as fact when there’s any doubt. – AD7six Feb 21 '22 at 07:17
  • Good point, I'll update the question but that was basically what I meant. – Macilias Feb 21 '22 at 07:50
  • git --version would be nice too – apflieger Feb 21 '22 at 11:08
  • git version 2.33.0 – Macilias Feb 21 '22 at 11:18
  • Do you still have submodules? a .gitmodules in the root? – apflieger Feb 21 '22 at 11:37
  • no, not at the root level, but there are some in subdirectories, I`ll update the question – Macilias Feb 21 '22 at 11:47
  • @matt what makes you thing it is - the message is the same but the context is different. – Macilias Feb 22 '22 at 10:20

1 Answers1

0

You have to have a ref named HEAD somehow.

Type that to list all refs on your repo:

git show-ref

I assume you will find a ref path ending by HEAD. Maybe refs/HEAD. Note that it is normal to have a HEAD for remote repos, like refs/remotes/origin/HEAD, leave it.

Copy that path and delete it with:

git update-ref -d refs/HEAD
apflieger
  • 912
  • 10
  • 18
  • Tried it but there was no `HEAD` in the outputted list. Had to do `git show-ref --head` then it's listed. – Romain Valeri Feb 20 '22 at 09:28
  • --head will output the standard HEAD which you don't want to delete (you can't anyway). – apflieger Feb 20 '22 at 15:01
  • Not at all, please read the description more closely, I already checked it, there is no branch containing HEAD in the name, not local and not in the origin - thats why its not the same question! – Macilias Feb 20 '22 at 15:03
  • 1
    Are you on a case sensitive file system? Could you have 2 files .git/HEAD and .git/head ? – apflieger Feb 20 '22 at 15:59
  • good idea, but its sadly not the case, I'll update the question with .git content – Macilias Feb 21 '22 at 08:04