0

This is likely a simple question but I am still learning and understanding GIT... It seemed to me by testing some things, that when you add a submodule to your Git repo, you can check in your branch and along with that you are checking in that added submodule so that you can push that to the remote repo and others checking out the repo will also get the added information about the submodule.

When I have that same repo and add another repo as a subtree instead, it seems to me that you are only adding that internal to your local GIT instance in that when I check in the branch I don't see any way that others checking out that repo will get information that will allow them to pull in that a subtree was added. Is that correct - that each user pulling the remote repo will have to manually add in the linking to the subtree?

jvoigt
  • 400
  • 4
  • 23

2 Answers2

1

git submodule init will pull the code from the submodules added after cloning the repository.

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

You will need to commit and push both the .gitmodules file and the submodule file.

When the git submodule init is done in the cloned repository, it fetches all the linked submodule code.

Mamtha Soni K
  • 895
  • 6
  • 9
  • I understand how submodule work. If you look closely i was asking how the same might work with subtrees – jvoigt Jul 07 '18 at 19:44
0

When using git subtrees, the entire repo of the subtree is merged into the parent repo in a subdirectory, so there's no extra commands other users will have to run to access the other repo content.

However, they won't see the history of the other repo, or track ongoing commits happening there. With git subtree it's more about having a marker in the history that makes it easy for the maintainer to push and pull changes made in the subtree, by merging and splitting them out selectively from the parent repo.

FWIW I've since moved on to git subrepo which I find to have all the same benefits with fewer downsides as git subtree. They work the same way though.

johnb003
  • 1,821
  • 16
  • 30