{"thread":{"id":"36037","subject":"submodules: reuse .git/modules/... for multiple checkouts of same URL","startedAt":"2014-03-03T12:24:23Z","lastAt":"2014-03-03T13:47:52Z","messageCount":2,"participants":["stefan.liebl@partner.bmw.de","Andrew Keller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"235870","messageId":"175C83AE67A6484B9A9351B9AE4D0662042809@smucm57a","threadId":"36037","inReplyTo":null,"subject":"submodules: reuse .git/modules/... for multiple checkouts of same URL","fromName":"","fromEmail":"stefan.liebl@partner.bmw.de","sentAt":"2014-03-03T12:24:23Z","receivedAt":"2014-03-03T12:24:23Z","isPatch":false,"sender":{"key":"stefan.liebl@partner.bmw.de","avatar":null},"body":"Hi,\n\nI have a git superproject with 3 submodules. The submodules are cloned from the same URL but use different branches. Git clones the repo three times and I have three entries in .git/modules. Is it possible to reuse the first clone for the next submodule clones?\n\nStefan\n"},{"id":"235871","messageId":"8C74E5C5-1330-4B57-9961-AF775C5A8BB2@kellerfarm.com","threadId":"36037","inReplyTo":"175C83AE67A6484B9A9351B9AE4D0662042809@smucm57a","subject":"Re: submodules: reuse .git/modules/... for multiple checkouts of same URL","fromName":"Andrew Keller","fromEmail":"andrew@kellerfarm.com","sentAt":"2014-03-03T13:47:52Z","receivedAt":"2014-03-03T13:47:52Z","isPatch":false,"sender":{"key":"andrew@kellerfarm.com","avatar":"https://avatars.githubusercontent.com/u/304204?v=4"},"body":"On Mar 3, 2014, at 7:24 AM, <Stefan.Liebl@partner.bmw.de> wrote:\n\n> I have a git superproject with 3 submodules. The submodules are cloned from the same URL but use different branches. Git clones the repo three times and I have three entries in .git/modules. Is it possible to reuse the first clone for the next submodule clones?\n\nSort of - but I don't think you'll like the side effects.\n\nIf each of the submodules are checked out on a different branch, then HEAD is going to be different in each repository in .git/modules.  So, each of the repositories in .git/modules are unique.\n\nYou could share the objects database (see --shared or --reference) which would dramatically reduce the size of each repo on its own, but that comes with a side effect: because there is no communication between any of the repositories involved in sharing objects, git-gc will happily delete an object that may be unneeded locally, but another repository will suddenly think it's corrupt.\n\nYou could also customize the refspecs in each repository.  For example, if one of the submodules has only 'origin/contrib' checked out, then you could change the refspec to '+refs/heads/contrib:refs/remotes/origin/contrib', which will cause only the objects pertaining to that branch will be downloaded.  This has the most benefit when the commit graph is orphaned in some way.  However, this approach requires manual labor every time you initialize a submodule.\n\n - Andrew Keller\n"}]}