Jason Grout
Jason Grout

Reputation: 631

How can I get git clone --recursive A B to use the submodule repositories in A?

It seems that if project A has submodules with remote urls, then git clone --recursive A B insists on pulling down copies of each submodule repository from the remote url. Is there a way to get git to clone the submodule repositories from the copies in A instead of pulling from the remote repositories?

I suppose I could do something like:

git clone A B
cd A
git submodule --quiet foreach 'echo [submodule \"$path\"]\\n path = $path\\n url = $toplevel/$path ' > ../B/.gitmodules
cd ../B
git submodule sync
git submodule update --init --recursive
git checkout .gitmodules
cd ..

Is there an easier way?

Upvotes: 4

Views: 215

Answers (1)

GoZoner
GoZoner

Reputation: 70155

Everything is local?

cp -r A B

[response to comment]

If A is dirty, then:

   (cd A; git stash)
   cp -r A B
   (cd B; git stash drop)
   (cd A; git stash apply)

Upvotes: 1

Related Questions