I was setting up a project with one submodule on my working iMac and was wondering how to do this most quickly. After tweeting the approach I had found, there where quickly some very smart people responding on how to do that better. I found this kind of crowd-sourced incremental improvement exhilarating, so I’m sharing it with you.
Being a git beginner I started out with the slowest approach, one step after each other.
git clone URL cd FOLDER git submodule init git submodule update
This first clones the main project, then setup the submodule and then we have an update pull the submodule code.
Simon Ljungberg was the first to point out that I could save one step by contracting both submodule commands like this.
git clone URL cd FOLDER git submodule update --init
The question did arise why the init would be necessary, but I found that if you don’t init the submodule then the update does not do anything and the submodule folder stays empty.
We already thought to have found the shortest possible method, comes along Alex Blewitt and informs us that – provided you use git 1.6.5 or higher – the whole affair can also be shortend in a single line:
git clone --recursive URL
Of course we all use a git that is way newer than this minimum requirement, mine is 126.96.36.199 as of this writing. So let’s take notice of the elegance of the recursive option and use this from now on.