0

I have a git submodule. On the server I have set it up, everything is working fine. On a different server, it's not finding the revision in the submodule it should go to. All changes have been pushed to the remote repository. I tracked the problem down to the remotes, that I might have screwed up while setting them up.

On the server where everything is working:

$ cat .gitmodules 
> [submodule "foo/submodule"]
>         path = foo/submodule
>         url = https://:@gitlab.server.com:8443/goodremote/submodule.git
$ cd foo/submodule/
$ git remote -v
> origin  https://:@gitlab.server.com:8443/goodremote/submodule.git (fetch)
> origin  https://:@gitlab.server.com:8443/goodremote/submodule.git (push)
> upstream        https://:@gitlab.server.com:8443/badremote/submodule.git (fetch)
> upstream        https://:@gitlab.server.com:8443/badremote/submodule.git (push)

The commit that is checked out resides on the origin remote, so I believe the .gitmodules is correct.

But here's what happens on the server where it's not working:

$ cat .gitmodules
> [submodule "foo/submodule"]
>         path = foo/submodule
>         url = https://:@gitlab.server.com:8443/goodremote/submodule.git
$ git submodule sync
$ git submodule update --init --recursive
> Initialized empty Git repository in foo/submodule/.git/
> remote: Counting objects: 13483, done.
> remote: Compressing objects: 100% (3001/3001), done.
> remote: Total 13483 (delta 10625), reused 13236 (delta 10444)
> Receiving objects: 100% (13483/13483), 103.89 MiB | 24.57 MiB/s, done.
> Resolving deltas: 100% (10625/10625), done.
> fatal: reference is not a tree: 71a57a9551a3c10229b92d724716a0f897001dab
> Unable to checkout '71a57a9551a3c10229b92d724716a0f897001dab' in submodule path 'foo/submodule'
$ cd foo/submodule
$ git remote -v
> origin  https://:@gitlab.server.com:8443/badremote/submodule.git (fetch)
> origin  https://:@gitlab.server.com:8443/badremote/submodule.git (push)

I understand the error message. The commit that is supposed to be checked out, is not to be found on that remote. However, I do not know how I can tell the submodule to use the right remote. Can I either define both remotes in the submodule or at least update the submodule to use the other remote? I believed this is what the .gitmodules is used for, but apparently it doesn't work.

Edit: I managed to fix this in an unsatisfactory way. I set up the repository including submodule on the new server until I hit the error outlined above. Then I go into the submodule, fix all the remotes and use git submodule update. While this is working, it is definitely not the way it is supposed to work. I'm puzzled.

pfnuesel
  • 10,855
  • 11
  • 51
  • 63
  • 1
    Are you sure the commit you're trying to check out has been pushed to the location where you are trying to check them out? Sub-modules have to be pushed separately when changes are made locally. – Dekker1 Nov 04 '16 at 13:09
  • Possible duplicate of [Git submodule head 'reference is not a tree' error](http://stackoverflow.com/questions/2155887/git-submodule-head-reference-is-not-a-tree-error) – 1615903 Nov 04 '16 at 13:10
  • @Dekker Yes, I pushed inside out, first the submodule then the outer repository. But as can be read in the output, it's really looking for the commit on the wrong remote, that's all. – pfnuesel Nov 04 '16 at 13:41
  • @1615903 This is not a duplicate. All the steps outlined in there, I've tried, as can be seen in my post. – pfnuesel Nov 04 '16 at 13:42
  • 1
    Ah true - retracted my close vote. – 1615903 Nov 04 '16 at 13:55
  • Why the downvote? – pfnuesel Nov 04 '16 at 16:02

0 Answers0