We Are All Monica
We Are All Monica

Reputation: 13344

How does git handle cloning another repository into a subdirectory?

I just cloned a repository into a subdirectory of another repository, and git actually appeared to handle the situation pretty intelligently. I know about submodules, but I thought they always had to be explicitly defined and I didn't think git had this functionality. What happened?

Here's my shell session:

https://gist.github.com/858131

Upvotes: 2

Views: 1159

Answers (2)

VonC
VonC

Reputation: 1324607

It handles it as a nested repository, not as a submodule.
As you found out, to declare it as a submodule:

  • the sub-directory shouldn't already exist, meaning if you already cloned your second repo, you need to delete it first before adding it as a submodule.
  • or you can try adding it directly in the .gitmodules file (not tested)

That will allow for the creation of the special entry in the git index referencing the submodule SHA1, as shown here, and detailed in the SO question "Nested git repositories without submodules?".

Upvotes: 2

Arrowmaster
Arrowmaster

Reputation: 9271

The second repository is being handled as a submodule by the first repository. Since you haven't defined it as a submodule though, you can not interact with it using the git submodule command, but all other commands treat it as a submodule.

Upvotes: 2

Related Questions