Search code examples
gitversion-controlgit-submodules

git submodule showing up as a file in git status


I added a submodule and when I run git status it shows up as a file

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   mysubmodule

should I commit this or add it to the .ignore file ?


Solution

  • Whenever there is a new submodule added, git creates a .gitmodules file and file for the submodule that you have added

    .gitmodules file stores the project URL and local subdirectory mapping.

    [submodule "mysubmodule"]
    path = Mysubmodule
    url = https://theurl
    

    Although Mysubmodule is a subdirectory in your working directory, Git sees it as a submodule and doesn’t track its contents when you’re not in that directory. Instead, Git sees it as a particular commit from that repository.

    So, You will need to commit both the .gitmodules file and the submodule file to git.

    Please refer to git documentation for more details.