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.