0

Let's say I have a repository test:

test.git

src/
    hello/
        awesome.c
    nice/
        cool.c
        fun.c
.gitignore
README.md

I would like to add src/hello/ to another repository (exactly like a submodule but not the main path (/src/hello/ instead of /)

test2.git

ok/
hello/ (submodule - links to test/src/hello)
    awesome.c
.gitmodules
.gitignore

Something like: (test2 git shell)

$ git submodule add https://github.com/username/test/src/hello

lordcommander
  • 150
  • 2
  • 7
  • Sounds like you may want to [sparse checkout your submodule](https://stackoverflow.com/questions/6238590/set-git-submodule-to-shallow-clone-sparse-checkout) – Cory Kramer May 11 '21 at 19:12
  • Git does not support this. You can, however, add the entire repository as a submodule and use some sort of checkout script and/or symbolic link trickery (the symlinks have to be in the superproject unless you have direct control of the submodule). – torek May 12 '21 at 01:07

1 Answers1

0

Maybe this helps:

git submodule add -b master -m "Added hello submodule" -- src/hello git commit -m "Added hello submodule" git push

git remote add -f test2 git://test.git

git fetch test2 git merge test2/-m "merge with test2" git push

please read the official documentation: https://git-scm.com/book/en/v2/Git-Tools-Submodules