Fix 'Filename too long' on Windows
git clone fails on Windows with 'Filename too long' — how do I fix it?
If you’re seeing this error
error: unable to create file <path>: Filename too longfatal: cannot create directory at '<path>': Filename too longwarning: Clone succeeded, but checkout failed.You’re in the right place — the fix is below.
Short answer
Windows caps paths at 260 characters unless both Git and Windows are told otherwise. Run git config --system core.longpaths true in an administrator terminal, and enable LongPathsEnabled in the registry. Then re-run git checkout in the half-cloned folder — the objects are already downloaded, only the file writing failed.
git config --system core.longpaths true
git checkout . # finish the checkout that failed
Run the first line from an elevated terminal, then finish the checkout
Does this match your situation?
- 'error: unable to create file ...: Filename too long'
- 'warning: Clone succeeded, but checkout failed.'
- The cloned folder exists but is empty or only partly populated.
- Only deeply nested paths fail — node_modules, generated code, vendored dependencies.
- The same repository clones fine on macOS or Linux.
Step-by-step fix
Turn on long paths in Git
Git for Windows can use the extended path API, but does not by default. The system scope needs an administrator terminal and covers every repository; --global works for just your account if you cannot elevate.
step 1git config --system core.longpaths true # no admin rights? your account only: git config --global core.longpaths true # just this clone: git clone -c core.longpaths=true <url>Turn on long paths in Windows itself
Git's setting only helps if Windows accepts the paths too. This has been supported since Windows 10 build 1607, but it is opt-in and off by default. A restart, or at least a new terminal, is needed afterwards.
step 2# PowerShell as Administrator: New-ItemProperty -Path 'HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem' \ -Name 'LongPathsEnabled' -Value 1 -PropertyType DWORD -ForceGroup Policy equivalent: Computer Configuration → Administrative Templates → System → Filesystem → Enable Win32 long paths.
Finish the checkout you already have
'Clone succeeded, but checkout failed' is good news: every object was downloaded and the repository is complete. Only writing the files out failed, and that step can simply be repeated once the limits are lifted.
step 3cd <repo> git config core.longpaths true git checkout . git statusOr shorten the path you clone into
The limit applies to the whole absolute path, so where you clone matters as much as what is inside the repository. Cloning to a short root buys back the length that C:\Users\<name>\Documents\Projects was spending.
step 4cd C:\src git clone <url> proj # or map a drive letter to a deep folder: subst X: C:\Users\me\very\deep\pathIf only some files are unwanted, check them out selectively
When the offending paths are generated output or an optional package you do not need, sparse checkout skips writing them entirely while keeping the repository intact.
step 5git clone --no-checkout <url> cd <repo> git sparse-checkout set src docs git checkout
Why this works
The 260-character MAX_PATH limit is not Git's — it comes from the original Win32 file APIs, and it counts the whole absolute path, so a repository that is perfectly legal on Linux becomes unclonable purely because of where you put it. Modern Windows can accept longer paths through the Unicode versions of those APIs, but only when the application opts in and the machine has the policy enabled, which is why both settings are needed. What makes this recoverable is that Git downloads objects first and writes files second: the pack containing your entire history transfers fine, and only the final checkout hits the filesystem. That is why 'Clone succeeded, but checkout failed' really does mean the hard part is done.
If that didn’t work
- Some tools bundle their own Git — check git --version and configure the one your IDE actually runs.
- Older Git for Windows builds handled long paths poorly; upgrade before spending time on anything else.
- Windows Explorer and some antivirus tools still cannot delete long paths — use git clean -fdx from inside the repository.
- As a last resort, rename the offending directories in the repository and commit shorter paths.
How to stop it happening again
- Clone into a short root such as C:\src rather than a deep Documents folder.
- Set core.longpaths and LongPathsEnabled once when you set up a Windows machine.
- Keep generated output out of the repository — node_modules and build folders cause most of these.
- Avoid very long directory names in a codebase that Windows users will clone.
Commands used in this guide
git configRead and write Git settings for one repo, your user, or the whole machine.
git cloneCopy a remote repository, its full history and its branches, onto your machine.
git checkoutThe old all-in-one: switch branches, restore files, or detach HEAD.
git sparse-checkoutCheck out only part of a huge repository.
git cleanDelete untracked files and directories from your working tree.
Still stuck?
Search the full command reference and every other rescue guide — there are 76 of them, covering everything from detached HEAD to force-push disasters.
Browse all guides →Frequently asked questions
How do I fix 'Filename too long' in Git on Windows?
Run git config --system core.longpaths true from an administrator terminal, and set the LongPathsEnabled registry value under HKLM\SYSTEM\CurrentControlSet\Control\FileSystem to 1. Both are needed — Git's opt-in does nothing unless Windows accepts long paths too.
What does 'Clone succeeded, but checkout failed' mean?
Git downloaded the whole repository successfully and only failed while writing files to disk. Nothing needs re-downloading: fix the path limit, then run git checkout . inside the folder to finish writing the working tree.
Why does the same repository clone fine on macOS and Linux?
Because the 260-character MAX_PATH limit is a Windows API constraint, not a Git one. macOS and Linux allow roughly 4096 characters, so a path that is unremarkable there can be impossible to create on Windows.
Can I fix this without administrator rights?
Partly. git config --global core.longpaths true works for your account, and cloning into a short folder such as C:\src often gets you under the limit on its own. The registry change does need elevation.
Does core.longpaths help with tools other than Git?
No — it only affects Git's own file operations. Explorer, some editors and many build tools still choke on long paths, so a short clone location remains the more robust fix.
Related rescue guides
Cloning takes forever — how do I clone a big repo faster?
Use --filter=blob:none for a partial clone that fetches file contents lazily, and add sparse-checkout to materialise only the directories you need. --depth 1 is fastest of all but gives you no usable history.
Read the fix →Always fixablegit status says every file changed but I didn't touch them — how do I fix line endings?
Windows writes CRLF and Unix writes LF, and without a policy Git records whichever your editor produced. Commit a .gitattributes with `* text=auto`, then renormalise the repository once — this fixes it for everyone, unlike the per-machine core.autocrlf setting.
Read the fix →Always fixableI renamed a file's case and Git won't notice — how do I fix it?
Windows and macOS filesystems treat Player.cs and player.cs as the same file, so a case-only rename is invisible to Git. Use git mv -f to force it, or rename via a temporary name, then commit — otherwise the wrong case ships to your Linux CI and the build breaks.
Read the fix →Always fixableCloning or pushing dies with 'RPC failed' or 'the remote end hung up unexpectedly' — how do I get it through?
The connection dropped part-way through a large transfer. Nothing is damaged. Clone shallow to make the transfer small enough to finish (git clone --depth 1), then deepen it with git fetch --unshallow. Switching the remote to SSH avoids the HTTP layer entirely and fixes most stubborn cases.
Read the fix →