Add repository to a git tree
I have a git repository online and I use, as many do, to keep track of my programs. It worked all fine with the usual procedure from the root of my directory's tree:
git add . git commit git push origin master
When one day I found a subdirectory in my tree have become green (on the git site) and was impossible to access. Now I know the green color is for a submodule (even if I have not understood what this mean) but I'd like it to be a real directory, one where I can view and download what's there or examine modifications. The question is, how can I make this directory to become normal again, with all its subdirectory and file inside without touching the other directories inside the tree?
The idea would be to:
- clone your repo
- git submodule update --init --recursive: see "How can I init/update git submodules in a remote?"
- remove and add again your files from the submodule: see "un-submodule a git submodule"
The last link shows you how to dereference a submodule, while, if you want, preserving the history of the commits done in said submodule (but merging them back to the main repo)
Now if, when trying to init the submodule, you get the message:
No submodule mapping found in .gitmodules for path '...'
Check the second part of "Git - how to track untracked content?": the "Replace It with Plain Content" section.
The root cause is when you try to add a directory which is a git repo in itself within your main git repo work tree:
The directory 'nested repo' starts out as an independent Git repository. Usually such sub-repositories are ignored, but if you tell git add to explicitly add it, then it will create an gitlink entry that points to the sub-repository’s HEAD commit instead of adding the contents of the directory. It might be nice if git add would refuse to create such “semi-submodules”.