This Git error occurs when a submodule is registered in the Git index but lacks a corresponding URL entry in the .gitmodules file. The path exists as a gitlink (special directory entry) but Git cannot locate the remote repository to fetch its contents. Fix it by either adding the missing submodule configuration or removing the stale gitlink entry.
The "No url found for submodule path in .gitmodules" error indicates a mismatch between Git's internal tracking and the submodule configuration file. When you run `git submodule update`, `git clone --recursive`, or similar commands, Git detects a path in the repository that's marked as a submodule (gitlink with mode 160000), but cannot find the corresponding URL definition in `.gitmodules`. This state typically occurs when: 1. **A submodule was incompletely removed** - the entry was deleted from `.gitmodules` but the gitlink in the index wasn't removed 2. **A merge conflict affected .gitmodules** - one branch had the submodule, another didn't, and the merge left the configuration inconsistent 3. **Files were copied from another repository** - directory contents were copied but the submodule relationship wasn't properly established 4. **The .gitmodules file is missing or misplaced** - it must be in the repository root directory Git uses a two-part system for submodules: the gitlink entry in the index (tracking the commit SHA of the submodule) and the `.gitmodules` file (storing the URL and path mapping). Both must be in sync for submodule operations to work.
First, identify exactly which submodule paths are causing the issue:
# List all gitlinks (submodule entries) in the index
git ls-files --stage | grep 160000
# Example output:
# 160000 abc123... 0 lib
# 160000 def456... 0 vendor/plugin
# Check what's in .gitmodules
cat .gitmodules
# Compare - any path in ls-files but not in .gitmodules is the problemThe gitlink mode 160000 indicates a submodule. If a path appears in the ls-files output but has no corresponding [submodule "path"] section in .gitmodules, that's your culprit.
If the submodule should exist and you know its source URL, add the missing configuration to .gitmodules:
# Add the submodule entry to .gitmodules
# Replace with your actual path and URL
git config -f .gitmodules submodule.lib.path lib
git config -f .gitmodules submodule.lib.url https://github.com/example/lib.git
# Or manually edit .gitmodules to add:
# [submodule "lib"]
# path = lib
# url = https://github.com/example/lib.git
# Sync the configuration to .git/config
git submodule sync
# Initialize and update the submodule
git submodule update --init
# Stage and commit the fixed .gitmodules
git add .gitmodules
git commit -m "Fix missing submodule URL configuration"Make sure the URL is accessible and the path matches exactly (including case sensitivity).
If the submodule is no longer needed, remove the orphaned gitlink from the index:
# Remove the gitlink from Git's index (cached)
git rm --cached lib
# If there's an entry in .git/config, remove it too
git config --remove-section submodule.lib 2>/dev/null || true
# If the directory exists and should be removed
rm -rf lib
# Commit the removal
git add -A
git commit -m "Remove stale submodule entry for lib"The --cached flag removes only the index entry without touching the working directory, which is safer if you're unsure about the contents.
The .gitmodules file must be in the repository root. Verify its location and that it's tracked:
# Check if .gitmodules exists at root
ls -la .gitmodules
# Check if it's tracked by Git
git ls-files .gitmodules
# If .gitmodules is not at root, find it
find . -name ".gitmodules"
# If found elsewhere, move it to root
mv path/to/.gitmodules ./.gitmodules
git add .gitmodulesIf .gitmodules doesn't exist at all but should, you'll need to recreate it with the proper submodule entries.
If this error appeared after a merge, the .gitmodules file may have conflict markers or missing sections:
# Check .gitmodules for conflict markers
grep -n "<<<<<<" .gitmodules
grep -n "======" .gitmodules
grep -n ">>>>>>" .gitmodules
# View the file for any issues
cat .gitmodules
# If you need to see the submodules from different branches:
git show main:.gitmodules
git show feature-branch:.gitmodules
# After manually fixing .gitmodules:
git add .gitmodules
git submodule sync
git submodule update --initMerges can sometimes drop submodule entries entirely if one branch didn't have them. You may need to manually combine entries from both branches.
If working with a shallow clone (common in CI/CD), the .gitmodules file might not be available:
# Check if repo is shallow
git rev-parse --is-shallow-repository
# If true, unshallow to get full history
git fetch --unshallow
# Then try submodule operations again
git submodule update --init --recursiveFor CI/CD pipelines, configure full checkout:
GitHub Actions:
- uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursiveGitLab CI:
variables:
GIT_SUBMODULE_STRATEGY: recursive
GIT_DEPTH: 0If the submodule state is badly corrupted, you can reinitialize everything:
# Remove all submodule configurations from .git/config
git config --local --remove-section submodule.lib 2>/dev/null
# Deinitialize all submodules
git submodule deinit --all -f
# Remove cached submodule directories
rm -rf .git/modules/*
# Reinitialize from .gitmodules
git submodule init
git submodule update --recursive
# If specific submodule still fails, add it fresh:
git submodule add https://github.com/example/lib.git libThis approach starts fresh while preserving your .gitmodules configuration.
### Understanding Git Submodule Architecture
Git tracks submodules using three components:
1. Gitlink in index - A special entry (mode 160000) pointing to a specific commit SHA in the submodule repository
2. .gitmodules file - Stores the mapping between paths and remote URLs (committed to repo)
3. .git/config - Local submodule configuration (not committed)
The "No url found" error specifically means component #1 exists but component #2 doesn't have the matching entry.
# View the gitlink entry
git ls-tree HEAD lib
# 160000 commit abc123... lib
# View .gitmodules entry (should exist but doesn't in error case)
git config -f .gitmodules --get submodule.lib.url### Detecting Submodule State Issues
Use this script to audit submodule consistency:
#!/bin/bash
# List all gitlinks in index
echo "=== Gitlinks in index ==="
git ls-files --stage | grep "^160000" | awk '{print $4}'
echo ""
echo "=== Submodules in .gitmodules ==="
git config -f .gitmodules --get-regexp path | awk '{print $2}'
echo ""
echo "=== Submodules in .git/config ==="
git config --local --get-regexp submodule | grep ".path" | awk -F= '{print $2}'### Case Sensitivity Issues
On case-insensitive filesystems (macOS, Windows), path case mismatches can cause this error:
# .gitmodules has:
[submodule "Lib"]
path = Lib
url = ...
# But index has path as "lib" (lowercase)
# Git treats these as different pathsFix by ensuring exact case match:
# Remove incorrect case entry
git rm --cached lib
# Re-add with correct case
git submodule add https://... Lib### Submodule Absolute vs Relative Paths
Submodules should use relative paths in .gitmodules. Absolute paths can cause issues:
# Wrong - absolute path
[submodule "lib"]
path = /home/user/project/lib
url = ...
# Correct - relative path from repo root
[submodule "lib"]
path = lib
url = ...### Recovering Submodule URL
If you don't know the original submodule URL, try these approaches:
# Check .git/config for cached URL
git config --get submodule.lib.url
# Check git log for when submodule was added
git log --all --full-history -- .gitmodules
# View .gitmodules at that commit
git show <commit>:.gitmodules
# Check if submodule directory has .git info
cat lib/.git
# If it contains a gitdir path, check that location### Common CI/CD Submodule Patterns
Netlify - Add to netlify.toml:
[build]
command = "git submodule update --init --recursive && npm run build"Vercel - Use build settings or vercel.json:
{
"git": {
"submodules": true
}
}Docker - Include submodule init in Dockerfile:
RUN git submodule update --init --recursive### Preventing This Issue
1. Always use `git submodule deinit` before removing - don't just delete directories
2. Commit .gitmodules changes atomically - with the gitlink changes in same commit
3. Use `git submodule status` - regularly to verify consistency
4. Configure git hooks - to validate submodule state before commit
kex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git