Git operations fail when file paths exceed system-imposed limits, typically the 260-character Windows MAX_PATH constraint. This affects deeply nested directories and is common with submodules or node_modules on Windows.
This error occurs when Git encounters file paths that exceed the maximum path length supported by your operating system or filesystem. While Git itself has no inherent directory depth limitation, it must operate within the constraints of the underlying platform. On Windows, the traditional MAX_PATH limit is 260 characters total for the complete file path (including drive letter, directories, filename, and extension). This legacy limitation dates back to early Windows API design and remains the default behavior for compatibility reasons. When Git tries to create, checkout, or access files with paths exceeding this limit, operations fail with path depth errors. On Linux and Unix systems, while the limits are more generous (typically 4096 characters for total path length and 255 bytes per individual path component), extremely deep nesting can still cause issues. The error manifests most commonly in repositories with deeply nested directory structures, multiple levels of Git submodules, or build artifacts like node_modules that create excessive path depths.
On Windows, enable Git's long path support globally:
git config --global core.longpaths trueFor system-wide configuration (all users):
git config --system core.longpaths trueThis tells Git to handle paths exceeding the traditional 260-character Windows limit.
On Windows 10 (version 1607+) or Windows 11, enable long path support at the OS level:
Via Registry:
1. Open Registry Editor (regedit)
2. Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
3. Set LongPathsEnabled to 1
4. Restart your computer
Via Group Policy (Pro/Enterprise editions):
1. Open Local Group Policy Editor (gpedit.msc)
2. Navigate to Computer Configuration → Administrative Templates → System → Filesystem
3. Open "Enable Win32 long paths"
4. Set to "Enabled"
5. Restart your computer
Reduce the base path length by cloning closer to your drive root:
# Instead of:
# C:\Users\YourName\Documents\Projects\company\team\repo
# Use:
cd C:\
git clone https://github.com/user/repo.gitThis reduces the overall path length for all files in the repository.
If the issue involves deeply nested submodules, use shallow cloning:
git clone --depth 1 --shallow-submodules --recurse-submodules <repository-url>This limits the history depth and can reduce path complexity.
If you control the repository structure, refactor to reduce nesting:
- Move deeply nested files closer to the root
- Consolidate redundant directory levels
- Use symbolic links for shared resources instead of duplicating nested paths
- Consider restructuring build output directories
For example, instead of:
src/components/features/user/profile/settings/components/forms/inputs/Use:
src/components/user-profile-settings/## Platform-Specific Considerations
Windows:
- The 260-character limit is a legacy Windows API (MAX_PATH) constraint
- Modern Windows (10+) supports up to 32,767 characters when long paths are enabled
- Some applications may still not support long paths even when enabled system-wide
- Git Bash and WSL provide better long path handling than native Windows Git
Linux/Unix:
- No inherent Git directory depth limit beyond system constraints
- ext4 limits individual path components to 255 bytes
- Total path length typically limited to 4096 characters
- Different filesystems (btrfs, xfs) may have different limits
## Git Alternates Depth Limit
Git has a hardcoded limit of 5 levels for nested alternate object stores. This is separate from path depth and typically only affects advanced repository configurations using alternates.
## Build Tool Considerations
Node.js projects with deeply nested node_modules directories are particularly prone to this issue on Windows. Consider:
- Using npm dedupe to flatten dependency trees
- Enabling node-linker=hoisted in pnpm
- Using Yarn's Plug'n'Play mode to avoid node_modules entirely
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