Setup & configAlways fixable

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 long
fatal: cannot create directory at '<path>': Filename too long
warning: 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.

quick fix
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

  1. 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 1
    git 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>
    
  2. 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 -Force
    

    Group Policy equivalent: Computer Configuration → Administrative Templates → System → Filesystem → Enable Win32 long paths.

  3. 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 3
    cd <repo>
    git config core.longpaths true
    git checkout .
    git status
    
  4. Or 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 4
    cd C:\src
    git clone <url> proj
    
    # or map a drive letter to a deep folder:
    subst X: C:\Users\me\very\deep\path
    
  5. If 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 5
    git 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 config

Read and write Git settings for one repo, your user, or the whole machine.

git clone

Copy a remote repository, its full history and its branches, onto your machine.

git checkout

The old all-in-one: switch branches, restore files, or detach HEAD.

git sparse-checkout

Check out only part of a huge repository.

git clean

Delete 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

← All Git Rescue guides