K.Rice
K.Rice

Reputation: 609

Add one part of git repo as submodule to another

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.

Upvotes: 2

Views: 1607

Answers (3)

JoeyZhong
JoeyZhong

Reputation: 1

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.

Upvotes: 0

Adrian W
Adrian W

Reputation: 5036

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.

Upvotes: 2

Vishal Rajole
Vishal Rajole

Reputation: 1544

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

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

Upvotes: 0

Related Questions