Git fatal Pathspec is in submodule
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
fatal: pathspec is in submodule means the path you passed to a Git command belongs to a nested Git repository, not to the parent repository’s normal tracked files. The fix is usually to run the command inside the submodule itself or to update the submodule pointer from the parent repo instead of trying to manipulate submodule contents directly at the top level.
Why Git Raises This Error
A submodule is stored in the parent repository as a gitlink, which is essentially a pointer to one commit of another repository. From the parent repo’s perspective, it does not track every file inside that nested project individually.
So if you run a command like this from the parent repository:
and vendor/lib is a submodule, Git cannot treat src/file.c as a normal parent-repo path. It belongs to the child repository.
Verify That The Path Is A Submodule
Start by confirming the submodule status.
If the path is a submodule, you will see that the parent repository tracks the submodule directory as one entry rather than tracking the nested files individually.
Work Inside The Submodule
If you want to inspect, restore, or commit a file inside the submodule, change into that submodule and run Git there.
That works because you are now operating in the repository that actually owns src/file.c.
Update The Parent Repo Correctly
If the submodule itself moved to a different commit and you want the parent repo to record that new submodule revision, the workflow is two-step:
- update the submodule repository
- commit the new gitlink in the parent repository
From the parent repository’s point of view, you are not adding changed files inside the submodule. You are adding a new submodule commit reference.
Restore A Submodule To The Recorded Commit
If your goal is to discard local submodule drift and return to the commit recorded by the parent repository, run:
That resets the checked-out state of the submodule to the commit expected by the parent repository.
When The Error Appears During git add
A common mistake is trying to add a file under a submodule path from the parent repository.
This fails for the same reason: the parent repository does not own that file directly. Either add and commit inside the submodule, or add the submodule directory itself in the parent repository if the submodule commit changed.
Common Pitfalls
The most common mistake is forgetting that a submodule is a repository boundary. The parent repository tracks the submodule commit, not every file under it.
Another mistake is editing files inside a submodule and then expecting git status in the parent repo to explain the full nested change set. The parent usually only shows that the submodule has moved or is dirty.
A third issue is trying to fix the problem by removing the submodule directory manually. That usually creates a mess unless your real goal is to remove the submodule entirely.
Summary
- The error means the specified path belongs to a submodule, not to the parent repository.
- Run file-level Git commands inside the submodule itself.
- Use
git add submodule-pathin the parent repo only to record a new submodule commit reference. - '
git submodule update --init --recursiverestores submodules to the commits recorded by the parent.' - Treat submodules as repository boundaries when debugging Git pathspec errors.
Related reading
- Git fatal protocol 'https' is not supported
- Git fatal Reference has invalid format 'refs/heads/master
- Git, fatal The remote end hung up unexpectedly
- git fetch a remote branch
- Git, How to solve Permission denied (publickey) error when using Git?
- git ignore exception
- Git, Find the most recent common ancestor of two branches
- Git Find the most recent common ancestor of two branches
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.