I have a git project named G, which has multi branches named A, B, C... Then I add a submodule S in branch A, update it, and commit all the changes. So I have a .gitmodule file and a 'directory' also named S lying on my working directory, as well as some changes in .git/config to track the module's info.
Then if I directly checkout branch B, git will define the 'directory' S as an untracked directory. In my understanding, this is caused because in branch B there is neither .gitmodule nor any other config files that can define S as a submodule, so git just think it as an untracked directory.
This is kind of annoying. If I remove the directory S in branch B, then when I checkout branch A again, the submodule S is also changed. But I don't want to add either submodule S or directory S to branch B (or to any other branches except A).
So my question is, is there some way to just add a submodule in one branch, while not affecting the other branches?
I know I can "git submodule deinit S" before I checkout B when I was in branch A. But I think this is not so convenient. I just want to use the files in another project, why should I init and deinit it every time? Or is my understanding to the usage of submodule wrong?
I also think about adding the directory S to .gitignore in other branches, but this is even more inconvenient if there's many branches.
And I also also think about just copying the project S files to the branch A, and commiting them. But then I cannot track the changes in project S directly.
And I also also also think about using symbolic link of project S, which finally meets my need. But I still want to know if there is a way in git to solve this problem.
(I'm using git 2.17.1