Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git add submodule into existing directory

Tags:

I have a git repository in the parent folder. Lets call this folder "root". Then there is a sub directory in the folder, lets call it "child". What I want to do is clone a remote repository as a submodule into "child":

git submodule add [email protected]:username/repopath child/
git submodule add [email protected]:username/repopath ./child/

Both the above give me the error:

child already exists in the index

I tried removing the directory from being tracked:

git rm --cached .\child\*
git submodule add [email protected]:username/repopath child/

Then i get this error:

'child' already exists and is not a valid git repo

Any help would be most appreciated

Thanks

like image 964
pedrumj Avatar asked Feb 07 '17 17:02

pedrumj


People also ask

What is git submodule add?

Git submodules allow you to keep a git repository as a subdirectory of another git repository. Git submodules are simply a reference to another repository at a particular snapshot in time. Git submodules enable a Git repository to incorporate and track version history of external code.


1 Answers

First, try your submodule add command in a new clone, because your previous attempts might have left a partial state for submodule.

Second, try first

git rm -r --cached child

Then, add and commit.

Finally, try your git submodule command:

git submodule add -- [email protected]:username/repopath child

Add, and commit.

like image 63
VonC Avatar answered Sep 25 '22 10:09

VonC