I used to have a git repository (sub
) inside of a git repository (main
). I was happy. But, one sad day, in a spark of over-engineering fever, I decided to turn it into a submodule. Now I want to get back to the good old times: transform the submodule back to a simple subfolder, with the history of that project being tracked in the sub/.git
directory instead of having it in the main repository’s .git/modules/sub
folder. How can I do that?
git rm --cached sub
and git submodule deinit
both keep the history into .git/modules/sub
instead of moving it to sub/.git
. This question about un-submoduling differs from mine as it wants to integrate the submodule history into the main repository’s history, whereas I want to keep them separate. Reading the answers about removing a submodule, I also could not find how to keep the history of the submodule and transfer it to the embedded repository rather than losing it altogether.
Note that I do not want to push the history of sub
entirely to its corresponding remote: I want to keep some branches local (for confidentiality reasons). So, the local history of sub
is precious. I can’t simply delete everything related to sub
from main
and clone from the remote again (plus, fetching from the network what I already have locally would be inelegant, I’d rather avoid it unless it simplifies the process a lot).
I want to do this for simplicity reasons and because I do not want to keep a reference to a specific “current” commit of sub
in main
. Currently, each time I move the master
branch forward in sub
, main
will realize that something has changed into the submodule and annoy me about updating the submodule.
Check first if .git/modules/sub
can be renamed as sub/.git
You will have to edit the new sub/.git/config
file, in order to remove the core.worktree
setting.
But you should see your full sub history there.