18

I'm developing for an embedded project that has the Linux source tree as a submodule. I'm currently working on a non-development machine, so I'll never build with this repository; it's just for reference.

At one point I initialized the linux submodule (bringing in about 2.5GB of data), but now I want to reverse the process, leaving the linux submodule uninitialized in this repository. To be clear, I don't want to check in any changes to the submodule as far as Git is concerned; I just want my disk space back.

How can I do this? I could delete the ./linux and .git/modules/linux directories to get rid of all the unneeded data, but I suspect that will leave git righteously confused and annoyed.

EncryptedWatermelon
  • 4,788
  • 1
  • 12
  • 28
Daniel Griscom
  • 1,834
  • 2
  • 26
  • 50

1 Answers1

23

The first three steps of the following are how you permanently delete a submodule; the fourth step will tell git to restore the module, but not to reinitialize it.

1) Remove the submodule entry from .git/config:
git submodule deinit -f path/to/submodule

2) Remove the submodule repository from the superproject's .git/modules directory:
rm -rf .git/modules/path/to/submodule

3) Remove the submodule directory located at path/to/submodule:
git rm -f path/to/submodule

4) Tell git to discard the removal of the submodule; it will return the module to the "uninitialized" state, leaving it with no changes to be committed:
git checkout -- .

Source

Daniel Griscom
  • 1,834
  • 2
  • 26
  • 50
EncryptedWatermelon
  • 4,788
  • 1
  • 12
  • 28
  • 2
    on top of that if you run "git checkout -- .", you probably won't have changes related to removing sub module – Doğancan Arabacı May 01 '19 at 15:15
  • Thanks, @DoğancanArabacı. I've proposed an edit to the answer that includes your comment, and worked for me; would you make sure I got it right? Thanks. – Daniel Griscom May 01 '19 at 16:15
  • Also for future travelers, if you just want the working files removed you can stop after the first line. – Beeeaaar Mar 08 '21 at 18:26
  • 1
    Steps 1 and 2 directly answer the OP's question. Steps 3 and 4 are unnecessary and should not be included in the answer. – plwalsh88 Jan 10 '23 at 13:11