Varun Vats
Varun Vats

Reputation: 509

Git - different submodules in two different branches

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.

Upvotes: 2

Views: 1515

Answers (1)

VonC
VonC

Reputation: 1329512

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.

Upvotes: 1

Related Questions