FIX: error: cannot stat ‘…example.json’: Filename too long

Filenames too long in a main repository that you cannot update directly?

So, I ran in this issue when I tried to pull a new branch and tried to merge main into it. I had a list of files where the filename were too long, so I won’t share all of them with you, but here is one example.

I guess this can happen when you do a checkout, pull, sync etc.

error: cannot stat '...example.json': Filename too long

Let’s fix error: cannot stat ‘…example.json’: Filename too long

You can open Git Bash, PowerShell, or whatever IDE you’re using, most of the time you can run Git commands.

For a specific repository run:

git config core.longpaths true

And run the following if you want to do it for globally:

git config --system core.longpaths true

Since some IDE’s do not look at the –system, you can also change this in Git global scope:

git config --global core.longpaths true

Change it in the Windows Registry Editor

If you’re using Windows 10 or later, you can also enable long path support at the operating system level. Here’s how:

  1. Open the Registry Editor
    Press Win + R, type regedit, and hit Enter.
  2. Navigate to the LongPathsEnabled Key
    Go to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
  3. Enable Long Paths
    • Find the LongPathsEnabled entry.
    • If it doesn’t exist, right-click in the right pane, select New > DWORD (32-bit) Value, and name it LongPathsEnabled.
    • Set the value to 1 to enable long paths.
  4. Restart Your Computer
    After making this change, restart your computer for it to take effect.

Open Registry Editor and go to: Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem

And update LongPathsEnabled to 1.

FIX: error: cannot stat ‘…example.json’: Filename too long

Git Configuration: Setting core.longpaths to true tells Git to bypass the default Windows path length limitation.

Windows Configuration: Enabling long paths at the OS level ensures that all applications, including Git, can work with longer file paths.

Published by

Bas Wijdenes

My name is Bas Wijdenes and I work as a PowerShell DevOps Engineer. In my spare time I write about interesting stuff that I encounter during my work.

Leave a Reply

Your email address will not be published. Required fields are marked *