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

Re: GIT_WORK_TREE and GIT_DIR with git clone

From
Cosmin Apreutesei <cosmin.apreutesei@gmail.com>
Date
Jan 21, 2014, 21:37 UTC
Message-ID
<CAKJdRakBWR7ofvcc8uhQ09QwiAJs7uvRNwP3WyuF4ve7FWONgw@mail.gmail.com>
In-Reply-To
<xmqq4n4xulrm.fsf@gitster.dls.corp.google.com>
Hi, thanks for answering.
Show 12 quoted lines
>> I would like to be able to tell my users that they can simply do:
>>
>> git clone --git-dir=_/git/module1/.git module1-url
>> git clone --git-dir=_/git/module2/.git module2-url
>>
>> which will overlay the files from both modules into the current
>> directory, which from git's perspective is the work-tree for both
>> modules.
>
> Would there be a sensible semantics in the resulting working tree?
> Which repository would a new file in such a combined working tree
> belong to?
The developer would have to decide by way of `git add`.

Ignoring other repos' files would be done by way of local config option `excludesfile` (.gitignore is out).

To make it easier to work with git this way, a script that creates a subshell in the context of a repo can be done with something like `PS1="[$1 $PS1]" GIT_DIR=_git/$1/.git bash -i" -- git would then work as usual in that subshell for that specific repo, never leaving the working tree.

I successfully employed the above scheme with luapower[1] packages, which are all different and mostly unrelated libraries, but which need to be overlaid over a common directory structure. And that's just an example. I can think of many projects that are modularized and yet the modules need to place many files in many places to make a working system (web frameworks, the linux filesystem, etc.)

Currently, to clone a repo one has to do:

export GIT_DIR=_git/submodule/.git git init git config --local core.worktree ../../.. git remote add origin ssh://git@github.com/luapower/submodule.git git fetch git branch --track master origin/master git checkout

That's 6 commands for what could be:
    git clone --git-dir=_git/submodule/.git
ssh://git@github.com/luapower/submodule.git
Or even better:
    git clone --git-dirs=_git ssh://git@github.com/luapower/submodule.git
[1] http://luapower.com
Previous: Junio C Hamano
Message 3 of 3 in “GIT_WORK_TREE and GIT_DIR with git clone”
  1. Cosmin ApreuteseiJan 20, 2014
  2. Junio C HamanoJan 21, 2014
  3. Cosmin ApreuteseiJan 21, 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.