2

I need o duplicate one folder in my project o another. But when I try:

git submodule add ./first-folder ./second-folder/sumbodule

it fails with:

fatal: clone of '[email protected]:username/projectname.git/first-folder' into submodule path

Am I doing something wrong or it's impossible by default and I should just mount it somehow? Thanks.

asked Apr 8, 2019 at 8:03

3 Answers 3

2

You can only add entire repositories as submodules. See git submodule documentation. There is a parameter path but that applies to the path where the submodule appears in the 'superproject', not to a path inside the submodule.

To achieve what you want, you need to make the first-folder a separate git repository and include that as submodule to all of your projects.

answered Apr 8, 2019 at 9:07
0

From ./second-folder/sumbodule, try to execute below command:

cd ./second-folder
git submodule add <git@github ...> sumbodule
answered Apr 8, 2019 at 9:05
0

This is now possible with sparse-checkout and symbolic links. For more details on how this works, please check out this gist

https://gist.github.com/ZhuoyunZhong/2c08c8549616e03b7f508fea64130558

The general idea is that you first add the submodule, then set up sparse-checkout in the submodule to track only the folders or files you need. Then you could use symbolic links to "place" the folder wherever you want.

answered Nov 20, 2024 at 0:52
1

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.