This is a huge pain in the bum. I\'ve got this a few times before and I don\'t understand why. 5 mins ago the repo was fine and working, I move some files around (which is a
I had the same issue. Running git status in my root project's directory produced the following error:
fatal: This operation must be run in a work tree
fatal: 'git status --porcelain' failed in submodule js/object-subscribe
Running git status in the affected submodule (js/object-subscribe) would produce this error:
fatal: This operation must be run in a work tree
Running git init in that submodule's folder did it for me.
Delete the .git folder from the module. Please keep the backup of that folder if you want to use it future.
I know this is an old thread, but I just had the same problem and ended up solving in a different way. The git init didin't work for me.
Posting here, in case it's useful to anyone else.
My repository has two submodules. After rebasing I started getting the error fatal: git status --porcelain failed.
The solution was to verify the property worktree in every submodule config file - e.g. <repository-checkout>/.git/modules/<submodule-name>/config.
I had one invalid path for the worktree property. It was linking to an unexisting folder that was changed and merged to master - probably due an error resolving conflicts.
For me it was different, nor git init solved the issue nor the worktree was wrong.
The error that I had was
fatal: unable to create threaded lstat
fatal: 'git status --porcelain=2' failed in submodule ext/hdf5
The solution for me was git gc.
In case it helps anyone else, I just encountered the same issue and found that running git init in the project root fixed it.
In my case after moving moduleA/mySubmodule to moduleB/mySubmodule using git mv moduleA moduleB with git 2.12.2, I ran into the following error:
$ git status
fatal: Could not chdir to '[../]moduleA/mySubmodule': No such file or directory
fatal: 'git status --porcelain' failed in submodule mySubmodule
fatal: 'git status --porcelain' failed in submodule moduleB
Then I did the following (Maybe not in this order)
.gitmodules entry to moduleB.git/modules and rename old module foldermoduleB and delete submodules foldergit submodule sync and git submodule updateAfter that, I could run git status again without problems.