Recently I’ve been working on a Drupal project at work and a fellow co-worker wanted to piggy-back resources on a similar project. He sent me over the code for a custom module I was going to use on the project.
Only after committing and pushing the folder from my local git repo to the origin server did I notice the remnants of my co-workers .git folder. This cause git to treat the subfolder as a git submodule and ignore the contents of the subfolder as I push my project to the origin server.
Here is what you need to do in order to remove the submodule and add as a subfolder:
git rm --cached subfolder git add subfolder git commit -m "Enter message here" git push
Now the origin should be able to see the contents of the subfolder.
This is a super article – descriptive and right to the point. Thanks much!
Many thanks for the useful info! I understood that I had accidentally created a sub-module, but couldn’t figure out how to get rid of it until a Google search led me here!
Thank you very much for taking the time to share your solution!
OSX loadinator 08:23 $ git rm –cached SearchAccuracy
rm ‘SearchAccuracy’
OSX loadinator 08:24 $ git add SearchAccuracy
OSX loadinator 08:25 $ git commit -m ‘Re-add’ SearchAccuracy
error: unable to index file SearchAccuracy
fatal: updating files failed
OSX loadinator 08:25 $ # Damn. So close…
Thanks for sharing Henry. If anyone is getting errors about git not being able to update the index when they try and commit the new folders, try removing your .git/index file (back up first, just in case) and then doing git reset.
[…] (contained .git), you won’t have a .gitmodules file to edit, or anything in .git/config. In this case all you need […]
[…] (contained .git), you won’t have a .gitmodules file to edit, or anything in .git/config. In this case all you need […]
[…] (contained .git), you won’t have a .gitmodules file to edit, or anything in .git/config. In this case all you need […]
Thank you so much for this! Really helped me out!
This helped a lot! Also, sometimes it says “fatal: pathspec ‘subfolder’ did not match any files”.
In that case, do a ” add subfolder” and carry out the above steps.
Also, one can manually remove the “.git” folder in the submodule if it is stored in local disk. (It needs to be unhidden in file explorer). And then committed as a regular directory.
You saved me with this. Thanks!
Thank you! I accidentally committed a sub folder with .git file in it and Github save it as a submodule.. Now it’s solved.