I want to mimic behavior like svn:externals: I have a master project and I have some "common" code in another repository. With SVN I would do:
svn co <url>/src common
and my folder structure would be:
repo/common/*.cpp
Now with git + submodule + sparse checkout this is a lot more complicated and I have an extra subdirectory layer when I add the submodule;
git submodule add <url> common
now my folder structure is:
repo/common/src/*.cpp
repo/common/lib/...
with sparse checkout I can make sure only to checkout the src folder, but than I still have one more layer (src) compared to the svn:externals solution:
repo/common/src/*.cpp
is there a better solution for common code? Or a way to clean this up? I know that everything will be working; it's just not so clean...
You cannot avoid the extra folder from the submodule, but you can add a symbolic link (even on Windows) in order to find the content you want.
Add your submodule with its repo name:
git submodule add -b master /url/of/repo
Add a symlink:
ln -s repo/src common
Don't forget to add the '-b master
' if you want your repo to follow its master
branch.
This is possible since git 1.8.2: see "git submodule
tracking latest".
Even the Git 2.25 and its git sparse-checkout
command would not avoid the extra folder level "common
".