2

My super-project has two branches - master and dev. I initially had a submodule in both these branches, but now I need to keep it only in the dev branch. To do that, I switched to the master branch and removed it from there (following the instructions outlined here). Now every time I switch from the dev branch to the master branch, I get a message saying warning: unable to rmdir path/to/submodule: Directory not empty. Also, every time I do git status in the master branch, git lists the submodule under Untracked files.

Is there a way I can tell git not to complain about this submodule? I tried adding the submodule path to .gitignore in the master branch, but that doesn't seem to have helped. Also, I am curious why git does not complain when a folder exists in one branch and not in another, but it does when a submodule exists in one branch and not in another?

Edit: I did not delete the relevant section from the .git/config file when removing the submodule as I still wanted it in the dev branch.

Kara
  • 6,115
  • 16
  • 50
  • 57
Varun Vats
  • 489
  • 1
  • 4
  • 14

1 Answers1

1

You have more complete instructions on how to delete a submodule in this answer:

The point which trips most of the users trying to remove a submodule is:

git rm --cached path_to_submodule (no trailing slash)

That is because they generally deleted (simple OS rm command, not a git rm command) the path to the submodule, which means it is no longer visible.
And yet, it is still recorded in the index.


If you need to remove the submodule in one branch only (and keep it in the other), then you need to:

  • not modify .git/config: this is a local config used by the all repos (and all its branches): so no git submodule deinit here (that only cleans what is in .git regarding submodule).
  • remove the submodule entry in:
    • .gitmodules file (you can have different content of that file in different branches)
    • the index: git rm --cached path_to_submodule (no trailing slash): again a modification you do only in one branch.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Sorry I answered my question in a hurry; I am still looking for an answer. Won't the process described in that page delete the submodule from both my branches? I still want the submodule to exist in my dev branch though. Moreover, the description of the `submodule deinit` command seems like it is just a wrapper for the [commands I used](https://git.wiki.kernel.org/index.php/GitSubmoduleTutorial) – Varun Vats Jun 25 '13 at 01:56
  • @VarunVats sure, I have edited my answer to address your specific question. – VonC Jun 25 '13 at 05:15
  • Yes, that is exactly what I did. I did not delete the submodule section from my `.git/config` file. My problem is that every time I switch from the `dev` branch to the `master` branch, I get a message saying **warning: unable to rmdir path/to/submodule: Directory not empty**. Also, every time I do git status in the master branch, git lists the submodule under **Untracked files**. Is there any way I can get rid of these messages? – Varun Vats Jun 25 '13 at 22:24
  • @VarunVats regarding the git status, you could add a .gitignore (only in the master branch) in order to ignore the root directory of your (previous) submodule. – VonC Jun 26 '13 at 05:18