8

When you add a submodule to your git project - it adds a gitmodules file and pulls down the actual submodule and stores it in your project.

Do I need to commit the actual submodule that's pulled down or is it better to just commit the gitmodules file that describes the path to the submodule?

Ogen
  • 6,499
  • 7
  • 58
  • 124
  • 1
    The `.gitmodules` file stores the stuff needed to `git clone` the *repository*. What's missing is *which commit to check out*. That information is stored in the superproject repository as a *gitlink* entry (`mode 160000`, in various Git outputs, vs `mode 100755` or `100644` for regular files, for instance). You must commit the gitlink entry. It's not clear to me whether that's what you mean by "the actual submodule". – torek Mar 12 '18 at 05:28

1 Answers1

6

You will commit automatically both:

  • the .gitmodule
  • the gitlink (special entry in the index of the main repo) which records the SHA1 of that submodule.

This is reflected in the reverse process (when you want to remove a submodule from a Git repo)

torek
  • 448,244
  • 59
  • 642
  • 775
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250