Richard Tuin
Richard Tuin

Reputation: 4562

Unable to checkout git submodule path

I have a problem when working with git submodules.

Whenever i receive a new submodule reference from the upstream repository, executing git submodule update gives the following result:

fatal: reference is not a tree: dd208d46ecdd1ac0d2b2594a610fe4c9150fece1
Unable to checkout 'dd208d46ecdd1ac0d2b2594a610fe4c9150fece1' in submodule path 'submodule/path'

It is important to note that the submodule has several remotes, of which the upstream remote should be used to update the submodule reference tree. I'm guessing that my problem is there, but i am not sure.

My setup is the following:

Git project

Remotes:

  1. origin (my git fork)
  2. upstream (project repo)

Submodule "module", has remotes:

  1. origin (my git fork)
  2. upstream (project repo)

Does anyone know what is causing my problem?

Upvotes: 38

Views: 67672

Answers (10)

张馆长
张馆长

Reputation: 1859

update git from 1.8.3.1 to 2.34.1 works fine for me

Upvotes: -1

knight2016
knight2016

Reputation: 597

git submodule unable to checkout

Note:

You may need to check if your remote branch is Case Sensitive. eg: IB_Certs, but you are using ib_certs

I found that issue, and took a long time to find why, at last, I found it case sensitive.

Hopefully, this solves your problems.

Upvotes: 0

c80609a
c80609a

Reputation: 3

Adding git rm --cached <submodule-directory> helps me on gitlab:

.prepare_deploy: &prepare_deploy
  before_script:
    - bundle install -j $(nproc) --path vendor
    - which ssh-agent || (apt-get update -y && apt-get install openssh-client -y)
    - mkdir -p ~/.ssh
    - chmod 700 ~/.ssh
    - eval $(ssh-agent -s)
    - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
    - (echo "$SSH_PRIVATE_KEY" | base64 --decode) > ~/.ssh/id_rsa
    - chmod 600 ~/.ssh/id_rsa
    - git rm --cached <submodule-directory>
    - git submodule sync --recursive
    - git submodule update --init --recursive

Upvotes: 0

Make sure that the submodules were pushed

cd submodule-dir
git push

In my case, I had:

  • committed to the submodule
  • not pushed
  • committed to the parent with the updated submodules
  • pushed the parent

so it is no wonder that it could not be found.

Then, if you are using a web interface such as GitHub, you can also go to the submodule repository web page, and double check that the commit you need shows there.

push.recurseSubmodules on-demand

It is possible to automate pushes further with:

git push --recurse-submodules=on-demand

which also pushes submodules as needed, or starting with 2.7:

git config push.recurseSubmodules on-demand
git push

Upvotes: 7

parasrish
parasrish

Reputation: 4152

Another way could be, without the command line git options, but to do this manually. The scenario happens mostly, when the sub-module paths have been moved/replaced (but not properly), thereby still pointing to the old references in the locally checkout repositories.

1) Locate the repository, and the submodule

ls -la .git/modules
   rm -f .git/modules/<module-with-issue>

2) Remove the older local sub-module configurations

 gedit .git/config

(remove the sub-module url entry here)

It looks something like this;

 *[submodule "module-with-issue"]
       url = ...*

3) Now, fetch and update the submodules freshly git fetch git submodule update --recursive --init

Note: One may additionally have to remove, the locally checked-out submodule folder in your repository, before attempting submodule update.

Upvotes: 0

Trident D&#39;Gao
Trident D&#39;Gao

Reputation: 19762

just saw this problem when i forgot to push the changes in one of my submodules

make sure changes are pushed

Upvotes: 0

Rock Lee
Rock Lee

Reputation: 9576

My issue was I had uncommitted changes in the submodules in their build.gradle files (which I think were automatically changed). They showed up in the git diff. I just did git checkout . to reset the submodule repos to have no changes and then the git submodule update worked.

Upvotes: 1

Ben Kreeger
Ben Kreeger

Reputation: 6344

My issue is that upon a cat .gitmodules of my repo, I was pointing at the wrong remote for the submodule's repo (I had originally cloned it with the original remote, but then switched to a fork of it; the gitmodules file never updated to reflect the change).

Upvotes: 0

thaller
thaller

Reputation: 1298

When doing git submodule update, git tries to checkout the commit/tree which is saved in the super project (in your example, the one with commit id dd208d4...)

I think you get the error because within the submodule there no such object present. You have to make sure that it is there. Usually that means that you have to fetch/pull it from a remote first.

Probably you have to

git submodule foreach git fetch
git submodule update

or maybe

git fetch --recurse-submodules

Assuming, that the submodule is configured, so that it can fetch the missing commit from the remote origin. In the end, you must know, from where you can fetch the missing commit and you have to get it.

You could check, whether you have dd208d4... by doing something like:

cd ./module
git log dd208d46ecdd1ac0d2b2594a610fe4c9150fece1
git cat-file -p dd208d46ecdd1ac0d2b2594a610fe4c9150fece1
git ls-tree dd208d46ecdd1ac0d2b2594a610fe4c9150fece1

One possible cause for such a problem is, that the one who published the new commit from the super module, did not publish the necessary commits from the submodule. He has to publish the commits from the submodule first.

Upvotes: 43

protonss
protonss

Reputation: 27

I had the same problem and I resolved adding a new commit for parent project and push allCheck the Subproject commit and commit from your module

Upvotes: 1

Related Questions