padibro padibro - 2 months ago 53x
Git Question

Error at git checkout. Path too long

I have this error in Git when I try to checkout to another branch after clone the repo:

git -c diff.mnemonicprefix=false -c core.quotepath=false checkout develop

fatal: cannot create directory at 'node_modules/karma/node_modules/chokidar/node_modules/anymatch/node_modules/micromatch/node_modules/braces/node_modules/expand-range/node_modules/fill-range/node_modules/isobject/node_modules/isarray/build': Filename too long

folder is no longher important to tack into git
(I put the folder
) but I always have this error.

It seems a problem of too long path, because if I try to navigate in explorer I meet a windows error of too long path.


I put the folder nodemodules/ in .gitignore

You would need to:

  • put node_modules/ in .gitignore, not nodemodules/
  • record the deletion of the node_modules/ folder from the git repo

    git rm -r --cached -- node_modules/

Then you can commit, and try to checkout again.

The OP padibro confirms in the comments a version issue:

I have updated git from 1.7.x to 2.7.4 (embedded git of sourcetree on windows) and now works fine

As described in "Git cannot create a file or directory with a long path", PR 122 added core.longpaths in Git for Windows only for git 1.9.0 and more.