When I run git status on my repo I get fatal: Not a git repository: /my repo/.git/modules/docs
I\'ve checked and .git exists and contains HEAD with the
I finally sorted out that the issue was due to an issue with one of the submodules. Simply renaming the repo directory caused a conflict with that submodule. After seeing the discussion in How can I rename a git repository with submodules? I realized that cloning the repo is a better way to go instead of renaming the directory and that solved the issue with the submodule.
In my case the problem was the .git/HEAD file didn't point anywhere, it just contained a sequence of strange characters. I copied the contents of .git/ORIG_HEAD to .git/HEAD and it worked again.
Source
Following @ax003d answer, you could replace all old paths (old/path
) with the new path (new/path
) using this command:
find . -type f \( -name ".git" -o \( -path "*.git/modules/*" -name config \) \) -print0 | xargs -0 sed -i -e "s#old/path#new/path#g"
You might want to check what the old paths look like before replacing them:
find . -type f \( -name ".git" -o \( -path "*.git/modules/*" -name config \) \) -print0 | xargs -0 grep --colour "old/path"
Solution :
1) Look into the HEAD file (under .git) -> If it is corrupted (contains some random values), replace the content with this text 'ref: refs/heads/develop' (develop is the last branch I was working on)
2) try - git status.
3) If step 2 doesn't solve your issue, try these commands (may not work for all but worth a try)
rm -f .git/index git reset
4) git will give you unstaged files after reset. keep or discard as per your wish
I solved this issue by reseting all git-submodules with
rm -rf .git/modules
git submodule update --init
I was facing this issue with submodules as well, but after analyzing the two files
{submodule}/.git .git/modules/submodules/{submodule}/config
I realized that in my case this was not an issue.
After a little research I have found that in my case I had to add the git (command : module add git) and the error disappeared.