40

I ran into this error, and found very little documentation on how to fix it online. I got the error by trying to run the command git add ., and received this response:

fatal: unable to stat 'myPathToAFile': No such file or directory

coder
  • 10,460
  • 17
  • 72
  • 125
  • What exactly was in the current directory when you ran `git add .`? Did you have any files with unusual names? What OS are you using? And which error message did you really see, the one in the title (with `'*'`), or the one in the question (with `'myPathToAFile`)? – Keith Thompson Jan 04 '13 at 19:01

7 Answers7

39

To solve the problem, I removed the file from git, then re-added it by doing the following:

git rm "myPathToAFile"

git add .

git commit -am 'my commit'

Hope this helps someone else!

coder
  • 10,460
  • 17
  • 72
  • 125
  • 3
    I had a similar error using Xcode 5.1 when starting a new project with git version control via the wizard: `fatal: unable to stat 'foo.xcodeproj/xcuserdata/nbenes.xcuserdatad/xcschemes/.dat1ffc.01b': No such file or directory`. I couldn't find the file either so I skipped the `git rm` step, but `git add` and `git commit` got me back up and running. – Nick Benes May 13 '14 at 10:56
10

Try git checkout my_branch -f

As given here: http://www.nullreference.se/2010/08/20/git-merge-error-permission-denied/

Babu James
  • 2,740
  • 4
  • 33
  • 50
7

I had the same issue. I'm using Windows 7 and my problem was the "Maximum Path Length Limitation" (max 260 characters for the path) (see http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx#maxpath for more details).

My workaround was to shorten the classname a little bit.

Peti
  • 1,670
  • 1
  • 20
  • 25
  • 1
    I had the same problem on Window 8.1. Error message shows as "No such file or directory" or "did not match any files". – Spongeboy Jan 22 '15 at 23:23
5

Another cause for this problem on Windows might be reserved file names. I bumped on them when I tried to clone the Linux Kernel repository out of curiosity on my Windows 10 machine, and Git could not create aux.c and aux.h files.

So you cannot create any file (with any extension) or folder named: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9, case insensitive.

See: https://learn.microsoft.com/en-us/windows/desktop/fileio/naming-a-file#naming-conventions

Tejes
  • 144
  • 1
  • 10
2

None of the above worked for me.

Updating Git fixed the problem.

J.Tribbiani
  • 454
  • 3
  • 9
  • 1
    I tried every single answer here and this is the one that fixed it for me. Actually, there wasn't an update available, I just reinstalled git. – Daniel Kaplan Mar 12 '19 at 20:07
0

Similar to the comment by Tejes, I had this problem only with files called "aux.R", which I could not git pull onto a windows machine, while it works fine on my linux client.

I fixed it by renaming it to "auxiliary.R", works now without any problem.

  • 1
    That is exactly the same cause. Windows reserves those file *names* without taking the extension into account. – Tejes May 29 '20 at 15:51
0

This problem can occur if your shell is working from a folder that does not exist in the currently checked out branch.

I was on a feature branch and was accidentally no longer using git from the root directory, but rather from a directory that only existed in that feature branch. When then checkouting to the main branch (using vs code rainbow ui), git would give me this error.

The solution was to cd .. back to the root directory of the git repo.

The Coding Wombat
  • 805
  • 1
  • 10
  • 29