threads / discuss / 35693

GIT_WORK_TREE and GIT_DIR with git clone

Subject: GIT_WORK_TREE and GIT_DIR with git clone

## tl;dr

3 messages between Jan 20, 2014 and Jan 21, 2014.

replies: 2people: 2as markdown or json

Cosmin Apreutesei· Jan 20, 2014, 15:59 UTC · lore
Hi,

I would like to have git clone respect GIT_DIR (and --git-dir) so I can clone multiple repos into the same working directory (I know there was another request for this[1]).

The pattern here is big projects that are modularized into multiple git repositories, but supposed to be overlaid over a common directory structure.

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.

[1] http://article.gmane.org/gmane.comp.version-control.git/170073/match=git_work_tree+git_dir+git+clone
Junio C Hamano· Jan 21, 2014, 20:23 UTC · re: Cosmin Apreutesei · lore

Re: GIT_WORK_TREE and GIT_DIR with git clone

Cosmin Apreutesei <cosmin.apreutesei@gmail.com> writes:
Show 8 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?

Cosmin Apreutesei· Jan 21, 2014, 21:37 UTC · re: Junio C Hamano · lore

Re: GIT_WORK_TREE and GIT_DIR with git clone

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

← back to recent threads