1

I have encountered a situation that a git submodule is inside a folder which containing other folders that to be ignored. The structure is like the following:

lib/
  submodule-folder/
  other-folder/       # This is folder should be ignored

My question is that can I just add lib/ to .gitignore to achieve the goal of other-folder being ignored while the submodule still working as normal? Or should I exclude the submodule pattern in .gitignore such as

lib/*
!lib/submodule-folder/

I have tried the first way and the submodule seems to work well when using command like git submodule update, but is still not sure if this is correct since I cannot find reference for explaining that. Does anyone run into a situation like that?

Tsang-Yi Shen
  • 532
  • 3
  • 15

1 Answers1

1

If the submodule is already tracked (meaning its root folder lib/submodule-folder/ is already part of the Git history as a gitlink), then yes, you can add lib/ to a .gitignore.

That will ignore everything else within the lib/ folder.

To double-check the submodule folder is not ignored by any .gitignore rule, check that the following command does return nothing:

git check-ignore -v -- lib/submodule-folder

(no trailing slash in this instance)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250