coder
coder

Reputation: 10530

Git error fatal: unable to stat '*': No such file or directory

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

Upvotes: 41

Views: 51736

Answers (7)

The Coding Wombat
The Coding Wombat

Reputation: 815

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.

Upvotes: 0

Laurin Herbsthofer
Laurin Herbsthofer

Reputation: 248

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.

Upvotes: 0

J.Tribbiani
J.Tribbiani

Reputation: 530

None of the above worked for me.

Updating Git fixed the problem.

Upvotes: 2

Tejes
Tejes

Reputation: 143

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

Upvotes: 5

Babu James
Babu James

Reputation: 2843

Try git checkout my_branch -f

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

Upvotes: 9

Peti
Peti

Reputation: 1700

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.

Upvotes: 7

coder
coder

Reputation: 10530

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!

Upvotes: 40

Related Questions