[Git] Error: unable to create file (Invalid argument / Filename too long) — File system limitation — How to Fix It
Summary
error: unable to create file (Invalid argument / Filename too long) appears when Git fails to create or extract a file because its path or name exceeds the file system’s limits — most often on Windows, where the default maximum path length is 260 characters.
Context
This issue occurs mainly during git clone, git pull, or git checkout, when long directory trees or deeply nested structures exceed Windows' path constraints. The same message can appear for filenames with invalid or reserved characters (like * ? : < > |).
Probable Cause
- Total path length exceeds 260 characters (Windows default).
- Filename contains invalid characters not allowed by the OS.
- Repository cloned too deep in the directory hierarchy.
- Cross-platform filename incompatibility (e.g., Windows ↔ Linux).
Quick Fix
- Enable long paths in Git (Windows only):
git config --system core.longpaths trueOr manually edit
C:\Program Files\Git\etc\gitconfigand add:[core] longpaths = true - Move your repository closer to the drive root:
Example:
C:\repos\projectinstead ofC:\Users\YourName\Documents\Very\Long\Path\project. - Remove invalid characters from filenames:
Avoid:
* ? : < > |(invalid on Windows). - Re-run your Git operation:
git clone <repo> git pull git checkout <branch>
Example
# Error
$ git clone https://github.com/user/repo.git
error: unable to create file docs/very/deep/path/with/a/super/long/filename.txt: Filename too long
# Fix
$ git config --system core.longpaths true
$ git clone https://github.com/user/repo.git
# → success
Alternate Scenarios
- “Invalid argument” on Windows: Filename includes reserved symbols (e.g.,
*,?,:). - “Filename too long” on Linux/macOS: Uncommon, but can occur on mounted or FAT32-formatted drives.
- Cross-platform repos: Case-sensitive filenames (e.g.,
File.txtvsfile.txt) can break on Windows.
Pitfalls & Debug
- Symptom → Git refuses to clone large repos.
Fix → Enable
core.longpathsor shorten clone path. - Symptom → Invalid characters in file paths. Fix → Rename files before pushing from Linux to Windows environments.
- Symptom → Clone succeeds partially.
Fix → Run
git fsckor re-clone after fixing path issues.
Verification & Next Steps
# Check Git long path support
git config --list | grep core.longpaths
# Find long paths (Unix)
git ls-tree -r HEAD | awk '{print $4}' | awk 'length($0) > 200'
# Move repository and retry
mv /long/deep/path /short/path
Best Practices
- Keep directory hierarchies shallow for cross-platform compatibility.
- Enable
core.longpathsin all Windows environments. - Avoid special characters in file or folder names.
- Use consistent naming conventions across systems to prevent merge issues.
Sources
Git Documentation — core.longpaths
Stack Overflow — filename too long
Tool/Git, OS/Windows, Topic/File System Limits