'Why does git fail to fetch specific valid submodule for a given commit and how to fix it?
I have a git repo which has another one as a submodule dependency. In the root of my project (where the .git, .gitsubmodules etc. are) I called
git submodule update
This failed with the following message:
Fetched in submodule path 'src/framework', but it did not contain cc8c38e9d853491c672452d8dbced4666fc73ec8. Direct fetching of that commit failed.
where src/framework is a sub-directory of my project (PROJECT_ROOT/src/framework) and should be where the third-party repo lands. The given commit hash is a valid one.
I have also tried git clone --recursive <my-repo> but it fails too.
The contents of my .gitmodules is
[submodule "src/framework"]
path = src/framework
url = [email protected]:gh/framework.git
In addition to that I have to note the following important fact: due to recent updates in the framework repo my code breaks hence I really need to retrieve that specific version of it where things were working fine.
Solution 1:[1]
Running this command after cloning (and receiving the error) solved my problem:
git submodule update --force --recursive --init --remote
Of course this is not a good solution. It is better to find and solve the underlying problem, but if anyone is in hurry, this was worked for me.
Solution 2:[2]
My case was that the url of the submodule had changed and it was de-synchronized with the parent repo. We noticed we could clone the parent and the child would initialize without fail, but this particular instance of the repository was failing.
Fixed it by:
- Checking that the url was the right one in the
.gitmodulesfile - Calling
git submodule sync - Calling
git -C path/to/submodule fetch(if the submodule was already initialized) - Calling
git submodule update --init [--recursive] path/to/submodule(if the submodule has been deinit)
Solution 3:[3]
I do not know what the exact problem was but below worked for me: (4th step is the key I think)
- git submodule update --init --recursive
- git pull --rebase --recurse-submodules
- git submodule update --force --recursive --init --remote
- git submodule sync
- git submodule update --init --recursive
Solution 4:[4]
The problem for me was that the submodule was pointing to a personal (clone of a) repository hosted on github.
I had multiple host repositories containing a reference to the same submodule.
I had changed the HEAD of the submodule in one of those repositories and committed the repository. Unfortunately I had neglected to push the new submodule HEAD to github, so other instances of the repository didn't have a record of the latest head, even after git submodule update etc.
Solution 5:[5]
I started experiencing this intermittently in a (github-hosted) repo since February 2022. Possibly due to working in multiple worktrees on the same local git repository. I never configure or edit submodules, URLs or credentials. None of the submodule sync/--init solutions helped.
Eventually I found this to always fix submodule X:
Remove the checkout directory X itself (assuming you don't have any changes in it!).
Fix the corresponding plumbing directory, which is either
- .git/modules/X (normally), or
- .git/worktrees//modules/X (if you're in an additional worktree):
by either deleting it entirely, or only deleting:
- shallow and
- refs/remotes/origin (or just the files in this directory)
Restore everything with
git submodule update X
Solution 6:[6]
In my case, git config for the submodules has been updated into ssh. I updated the parent project's git config as well as its submodules to http.
Aside from that, I updated my git credentials using window's web credentials which you can search in windows settings.
Solution 7:[7]
When I experienced this error, it was caused by the submodule reference pointing to a commit that only existed locally.
Solution 8:[8]
I ended up just going:
- Going into the submodules repo
git pullfor latest- Going into the top repo root directory
git commmit -m "updated submodule"so the main repo is made aware.git push
After that my problems all disappeared. This also fixed my Netlify problems.
Solution 9:[9]
Below command solved the problem
- git submodule sync
Solution 10:[10]
check your system docs, on mine it is:
Mac_3.2.57$ping -S 10.0.0.148 -c 100000 1.1.1.1
PING 1.1.1.1 (1.1.1.1) from 10.0.0.148: 56 data bytes
64 bytes from 1.1.1.1: icmp_seq=0 ttl=59 time=25.521 ms
64 bytes from 1.1.1.1: icmp_seq=1 ttl=59 time=18.837 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=59 time=16.605 ms
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alim Giray Aytar |
| Solution 2 | Chnossos |
| Solution 3 | fargusto |
| Solution 4 | EoghanM |
| Solution 5 | |
| Solution 6 | ALBlancoIV |
| Solution 7 | |
| Solution 8 | mfaani |
| Solution 9 | Guru |
| Solution 10 | Andrew |
