9

Is it possible to download submodules for a repository with only the working directory?

If I download a tarball of a repository from GitHub, that is equivalent to a shallow clone without the .git folder, is it at all possible to "download" the submodules into the working directory?

I tried git init && git submodule update --init, but this neither initializes nor does it update the submodules. The .gitmodules file is in the current directory.

Update: Some more background on the question: We'd like to use tarballs for checking out repositories at Travis CI, but several people use git submodules. "Don't use Git submodules" would therefore not be a good answer, but the answer doesn't really have to be something maintainable either. I just want a folder that has the code checked out and with the submodules initialized, there's no need for anything that allows me to pull down more changes later.

sarahhodne
  • 9,796
  • 3
  • 39
  • 44
  • Why wouldn't a `git submodule update --init --recursive --force` be working? It should load those submodules (but with their full history). Note that [git1.8.4 will add a --depth for shallow submodule clone](http://stackoverflow.com/a/17692710/6309). – VonC Jul 25 '13 at 06:03
  • @VonC If only I knew. That command does nothing at all for me. No errors, but it returns "instantly" without any output. – sarahhodne Jul 25 '13 at 06:45
  • What is the content of your `.gitmodules` file? And what version of git are you using? – VonC Jul 25 '13 at 06:49
  • 1
    Here's an example with the commands to download the tarball and all: https://gist.github.com/henrikhodne/49bb2c11d2fe25b31089 – sarahhodne Jul 25 '13 at 06:59

1 Answers1

2

Combining a wget/tar approach, with a git init won't help you initialize submodules:

Everything is untracked after the git init.

You need to add and commit everything, before:

git submodule update --init --recursive --force

That git submodule command will then "work", but create only empty directories.
That is because the tar file didn't include the special entries (160000) created by a git submodule add.

You need to re-declare those submodules:

C:\prog\git\ReactiveCocoa-2.0-development>git submodule add --name xcconfigs https://github.com/jspahrsummers/xcconfigs.git external\xcconfigs
Cloning into 'external\xcconfigs'...
remote: Counting objects: 312, done.
remote: Compressing objects: 100% (229/229), done.
Receal 312 (delta 87), reused 306 (delta 82)
Receiving objects: 100% (312/312), 64.51 KiB | 0 bytes/s, done.
Resolving deltas: 100% (87/87), done.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • This still doesn't work for me. I'm using the same commands as the gist in the comment above, with `git add -A . && git commit -m "commit everything"` immediately after `git init`. – sarahhodne Jul 25 '13 at 07:43
  • Thanks, it looks like we have to parse the `.gitmodules` file then and readd everything. I was hoping for something slightly more automated, but I guess it will work. – sarahhodne Jul 25 '13 at 17:23