Question

I have a repo with a directory structure like so /foo /foo/bar /foo/bar/me /foo/bar/you /foo/one /foo/one/two /foo/one/three

There is a submodule I want to add that has this structure /foo/bar/file.txt /foo/one/otherfile.txt

Is there way to add that submodule to my repo, where the submodule shares some of the same directory structure? I've tried using the basic add submodule commands, but I get the error that 'foo' already exists in the index, which I take to mean that becuase my repo already has a /foo directory, it can't add the submodule with the same directory.

Is there anyway to have the submodule share the directory structure, but still have different files?

Was it helpful?

Solution

Check out the submodule into a subfolder, for example /foo/submodule, so it looks like this:

/foo/submodule/foo/bar/file.text
/foo/submodule/foo/one/otherfile.txt

Then simply link the files in your repo:

/foo/bar/file.txt --> link to ../submodule/foo/bar/file.txt
/foo/one/otherfile.txt --> link to ../submodule/foo/one/otherfile.txt

This could even be expanded to automatically update the links and remove dead links when you update the submodule by a git hook if necessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top