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.

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

cd ./second-folder
git submodule add <git@github ...> sumbodule

Comments

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.

1 Comment

Link-only answers are not good.. You can edit the answer and paste it here.

Your Answer

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.