git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: submodules: reuse .git/modules/... for multiple checkouts of same URL

From
Andrew Keller <andrew@kellerfarm.com>
Date
Mar 3, 2014, 13:47 UTC
Message-ID
<8C74E5C5-1330-4B57-9961-AF775C5A8BB2@kellerfarm.com>
In-Reply-To
<175C83AE67A6484B9A9351B9AE4D0662042809@smucm57a>
On Mar 3, 2014, at 7:24 AM, <Stefan.Liebl@partner.bmw.de> wrote:
> 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?
Sort of - but I don't think you'll like the side effects.
If 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.
You 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.
You 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.
 - Andrew Keller
Previous: stefan.liebl@partner.bmw.de
Message 2 of 2 in “submodules: reuse .git/modules/... for multiple checkouts of same URL”
  1. stefan.liebl@partner.bmw.deMar 3, 2014
  2. Andrew KellerMar 3, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.