Search code examples
gitgithubgit-submodules

In git, what may cause the error message " fatal: Unable to find refs/remotes/origin/HEAD revision in submodule path 'Assets/NRSDK'"


Example project:

https://github.com/hpvdt/HMD-nreal/tree/cleanup/dev1

When I checkout this project and try to synchronise with all its submodule, I got a very concerning error message:

git submodule update --remote --recursive
fatal: Unable to find refs/remotes/origin/HEAD revision in 
submodule path 'Assets/NRSDK'

It is concerning because refs/remotes/origin/HEAD is not a revision, nor it is a branch name.

What could possibly cause this defect? Is it a bug in git? I'm using git version 2.40.1.windows.1.


Solution

  • Since a submodule acts like a standalone repository once you are inside it, you can test the submodules directly. If you change directory (cd) to Assets/NRSDK while on the cleanup/dev1 branch of your super project, you can run git show-ref to see all the references it has. I also usually run git fetch -pv to make sure I’m seeing what’s on the remote server (the -p flag prunes stale references that no longer exist on the remote).

    The refs/remotes/origin/HEAD is a symbolic reference that denotes the latest commit on the default branch on the remote. If you run git show-ref from within either submodule you should see refs/remotes/origin/HEAD listed - if not, something may be wrong with your repository.

    The --remote flag instructs git-submodule update to update the submodule to the remote tracking branch. If you don’t have one specified in .gitmodules (or in config), it updates the submodule to the default remote HEAD, which is refs/remotes/origin/HEAD.