remove git submodule but keep files

Git

Git Problem Overview


I have a git submodule that I would like to become part of my main project (since I have a lot of project specific code that will go into the submodule).

So I'd like to remove the git references to the submodule and add the files to my main git repository.

But how ?

Git Solutions


Solution 1 - Git

You must remove the gitlink entry in your index:

mv subfolder subfolder_tmp
git submodule deinit subfolder
git rm --cached subfolder
mv subfolder_tmp subfolder
git add subfolder

Replace subfolder with the name of the folder for your submodule, and make sure to not add any trailing slash.

This is what I detail in "Remove a Git submodule?" and "un-submodule a git submodule".

The --cached option allows you to keep the subfolder content in your disk... except git submodule deinit would already have removed that content anyway. Hence the mv part.

You then can add and commit that subfolder.

Solution 2 - Git

First delete .git folder from the submodule.

Just running this removes the cashed folder and contents from git but won't delete the folder.

git rm -r --cached [EnterFolderNameWithoutBrackets]

Solution 3 - Git

The answer from VonC will delete the submodule folder contents unless you rename the physical folder first - as shown in this answer, whose question was noted to be a duplicate by Chad:

https://stackoverflow.com/a/16162228

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAskbarView Question on Stackoverflow
Solution 1 - GitVonCView Answer on Stackoverflow
Solution 2 - GitJoe ShakelyView Answer on Stackoverflow
Solution 3 - GitfractosView Answer on Stackoverflow