# [idea] separate .git dir and the working tree

12 messages from 2011-02-05 to 2011-05-23. Participants: redstun, Mike Gant, Jonathan Nieder, Jared Hance, Konstantin Khomoutov, Nicolas Sebrecht, Michael Witten.
Thread: https://gitlist.dev/t/26414

## redstun, 2011-02-05 02:53

Subject: [idea] separate .git dir and the working tree
Message-ID: <AANLkTik4MjnpOzPdGy7ZDiH0in4e1DpjrhQFOHjUiEEE@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTik4MjnpOzPdGy7ZDiH0in4e1DpjrhQFOHjUiEEE%40mail.gmail.com

```
First please shout if this is a known feature :-)

I think separating the .git directory from its working tree could
increase the safety of the data to one more level higher.

We might have a git variable set to specify (a shared place) where to
put the .git directories (or the data inside it), then use
"/path/to/working/tree" as (or the seed to calculate) a hash key to
map from the (.git directory in the) shared place to the working tree
directory.

Or we may have just a few data (that can be re-created) stored in the
.git directory along with the working tree, and most of the revision
history stored in the shared place.

```

## Mike Gant, 2011-02-05 03:23

Subject: Re: [idea] separate .git dir and the working tree
Message-ID: <20110205032339.GA15303@mg1>
URL: https://gitlist.dev/e/20110205032339.GA15303%40mg1
In-Reply-To: <AANLkTik4MjnpOzPdGy7ZDiH0in4e1DpjrhQFOHjUiEEE@mail.gmail.com>

```
On Sat, Feb 05, 2011 at 10:53:58AM +0800, redstun wrote:
> First please shout if this is a known feature :-)
> 
> I think separating the .git directory from its working tree could
> increase the safety of the data to one more level higher.
> 
> We might have a git variable set to specify (a shared place) where to
> put the .git directories (or the data inside it), then use
> "/path/to/working/tree" as (or the seed to calculate) a hash key to
> map from the (.git directory in the) shared place to the working tree
> directory.
> 
> Or we may have just a few data (that can be re-created) stored in the
> .git directory along with the working tree, and most of the revision
> history stored in the shared place.

GIT_DIR and GIT_WORK_TREE might be what you are looking for. Explanation
of usage in 'man git'

HTH
Mike

> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

```

## Jonathan Nieder, 2011-02-05 13:27

Subject: Re: [idea] separate .git dir and the working tree
Message-ID: <20110205132708.GA18391@elie>
URL: https://gitlist.dev/e/20110205132708.GA18391%40elie
In-Reply-To: <20110205032339.GA15303@mg1>

```
(restoring cc list; please do not cull cc's)

Mike Gant wrote:
> On Sat, Feb 05, 2011 at 10:53:58AM +0800, redstun wrote:

>> I think separating the .git directory from its working tree could
>> increase the safety of the data to one more level higher.
[...]
> GIT_DIR and GIT_WORK_TREE might be what you are looking for. Explanation
> of usage in 'man git'

The .git directory is allowed to be a symlink.  Or a file like so

	gitdir: /path/to/git/repo

for symlink-challenged operating systems.  See gitrepository-layout(7)
for details.

Cheers,
Jonathan

```

## redstun, 2011-02-05 14:24

Subject: Re: [idea] separate .git dir and the working tree
Message-ID: <AANLkTinYMuXSvKjgtpSCbJPuo=PHDGR_OgOkwtV4Azmz@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinYMuXSvKjgtpSCbJPuo%3DPHDGR_OgOkwtV4Azmz%40mail.gmail.com
In-Reply-To: <20110205132708.GA18391@elie>

```
Making .git a symbol link is nice.

Regarding the GIT_DIR variable, looks like it needs to be paired with
the GIT_WORK_TREE variable, does this mean that I can only have one
local git repository?

what I wanted is, I may have multiple git working tree in my $HOME, like:
$HOME/proj1
$HOME/proj2,

I then wanted their .git directories respectively located at
/safe/disk/.git_proj1
/safe/disk/.git_proj2

How can I get this? I tried to read the doc but didn't have much luck.

Thanks

On Sat, Feb 5, 2011 at 9:27 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> (restoring cc list; please do not cull cc's)
>
> Mike Gant wrote:
>> On Sat, Feb 05, 2011 at 10:53:58AM +0800, redstun wrote:
>
>>> I think separating the .git directory from its working tree could
>>> increase the safety of the data to one more level higher.
> [...]
>> GIT_DIR and GIT_WORK_TREE might be what you are looking for. Explanation
>> of usage in 'man git'
>
> The .git directory is allowed to be a symlink.  Or a file like so
>
>        gitdir: /path/to/git/repo
>
> for symlink-challenged operating systems.  See gitrepository-layout(7)
> for details.
>
> Cheers,
> Jonathan
>

```

## Jonathan Nieder, 2011-02-05 18:04

Subject: Re: [idea] separate .git dir and the working tree
Message-ID: <20110205180425.GA18961@elie>
URL: https://gitlist.dev/e/20110205180425.GA18961%40elie
In-Reply-To: <AANLkTinYMuXSvKjgtpSCbJPuo=PHDGR_OgOkwtV4Azmz@mail.gmail.com>

```
redstun wrote:

> what I wanted is, I may have multiple git working tree in my $HOME, like:
> $HOME/proj1
> $HOME/proj2,
> 
> I then wanted their .git directories respectively located at
> /safe/disk/.git_proj1
> /safe/disk/.git_proj2
> 
> How can I get this? I tried to read the doc but didn't have much luck.

By making .git in $HOME/proj1 a symlink to /safe/disk/.git_proj1 and
making $HOME/proj2/.git a symlink to /safe/disk/.git_proj2.
GIT_DIR should be left unset for this to work.

The GIT_DIR variable is for more complicated use cases in which you
do not want a .git directory, file, or symlink in the worktree at all.

One uses it as follows:

	GIT_DIR=/somewhere/else/.git git <command> ...

The top level of the work tree is inferred to be the current working
directory and git metadata is taken from somewhere else.

Sometimes a person does not only want to work in the top level of the
working tree.  To tell git where the top level is, use the
GIT_WORK_TREE variable:

	(
		GIT_DIR=/somewhere/else/.git; export GIT_DIR
		GIT_WORK_TREE=$(pwd); export GIT_WORK_TREE

		cd sub/directory
		git <command>...

		cd ../other/directory
		git <other command>...
	)

These are not variables for your .profile, since as you mentioned, a
person typically will work with one git repo and worktree sometimes,
another git repo and work tree another time.

Hope that helps,
Jonathan

Side note: I don't think you mentioned wanting it, but for reference,
there is a nice tool for sharing objects between multiple worktrees in
contrib/worktree.  It comes with some sharp edges, as described in [1].

[1] http://thread.gmane.org/gmane.comp.version-control.git/150559

```

## Mike Gant, 2011-02-06 00:20

Subject: Re: [idea] separate .git dir and the working tree
Message-ID: <20110206002009.GA13594@mg1>
URL: https://gitlist.dev/e/20110206002009.GA13594%40mg1
In-Reply-To: <20110205132708.GA18391@elie>

```
On Sat, Feb 05, 2011 at 07:27:08AM -0600, Jonathan Nieder wrote:
> (restoring cc list; please do not cull cc's)

My apologies, but I didn't see a cc list in the original. Please
explain.

-Mike

```

## Mike Gant, 2011-02-06 00:40

Subject: Re: [idea] separate .git dir and the working tree
Message-ID: <20110206004013.GB13594@mg1>
URL: https://gitlist.dev/e/20110206004013.GB13594%40mg1
In-Reply-To: <20110206002009.GA13594@mg1>

```
On Sat, Feb 05, 2011 at 05:20:09PM -0700, Mike Gant wrote:
> On Sat, Feb 05, 2011 at 07:27:08AM -0600, Jonathan Nieder wrote:
> > (restoring cc list; please do not cull cc's)
> 
> My apologies, but I didn't see a cc list in the original. Please
> explain.
> 
> -Mike

Never mind, I think I understand.

So does anyone use Mutt? And do they know a recipe to move the sender
address to the cc list? If not, I'll figure it out.

Thanks,
-Mike

```

## Jared Hance, 2011-02-06 01:00

Subject: Re: [idea] separate .git dir and the working tree
Message-ID: <1296954015.4048.0.camel@localhost.localdomain>
URL: https://gitlist.dev/e/1296954015.4048.0.camel%40localhost.localdomain
In-Reply-To: <20110206004013.GB13594@mg1>

```
On Sat, 2011-02-05 at 17:40 -0700, Mike Gant wrote:
> On Sat, Feb 05, 2011 at 05:20:09PM -0700, Mike Gant wrote:
> > On Sat, Feb 05, 2011 at 07:27:08AM -0600, Jonathan Nieder wrote:
> > > (restoring cc list; please do not cull cc's)
> > 
> > My apologies, but I didn't see a cc list in the original. Please
> > explain.
> > 
> > -Mike
> 
> Never mind, I think I understand.
> 
> So does anyone use Mutt? And do they know a recipe to move the sender
> address to the cc list? If not, I'll figure it out.
> 
> Thanks,
> -Mike
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

When I used Mutt, if I remember correctly, L did the job (list reply).

```

## Konstantin Khomoutov, 2011-02-06 10:49

Subject: Re: [idea] separate .git dir and the working tree
Message-ID: <20110206104952.GD20056@localhost.localdomain>
URL: https://gitlist.dev/e/20110206104952.GD20056%40localhost.localdomain
In-Reply-To: <1296954015.4048.0.camel@localhost.localdomain>

```
On Sat, Feb 05, 2011 at 08:00:15PM -0500, Jared Hance wrote:

> > > My apologies, but I didn't see a cc list in the original. Please
> > > explain.
> > Never mind, I think I understand.
> > So does anyone use Mutt? And do they know a recipe to move the sender
> > address to the cc list? If not, I'll figure it out.
> When I used Mutt, if I remember correctly, L did the job (list reply).
Also "g" is "group reply" -- it simply replies to all e-mails mentioned
in the mail which is being replied to.

```

## Nicolas Sebrecht, 2011-02-06 10:55

Subject: [idea] Re: separate .git dir and the working tree
Message-ID: <20110206105510.GA14195@vidovic>
URL: https://gitlist.dev/e/20110206105510.GA14195%40vidovic
In-Reply-To: <20110206004013.GB13594@mg1>

```
The 05/02/11, Mike Gant wrote:

> So does anyone use Mutt? And do they know a recipe to move the sender
> address to the cc list? If not, I'll figure it out.

g (group answer).

-- 
Nicolas Sebrecht

```

## Mike Gant, 2011-02-07 04:57

Subject: Re: [idea] Re: separate .git dir and the working tree
Message-ID: <20110207045757.GC13594@mg1>
URL: https://gitlist.dev/e/20110207045757.GC13594%40mg1
In-Reply-To: <20110206105510.GA14195@vidovic>

```
On Sun, Feb 06, 2011 at 11:55:10AM +0100, Nicolas Sebrecht wrote:
> The 05/02/11, Mike Gant wrote:
> 
> > So does anyone use Mutt? And do they know a recipe to move the sender
> > address to the cc list? If not, I'll figure it out.
> 
> g (group answer).
> 

Thanks. I knew about L (list reply) and g (group reply). L only replies
to the list address, git@vger.kernel.org, in this case. Certainly, g is
the closest behavior as long as it is acceptable to have the sender name
in the To: header along with the list address (as in this response).

On the other hand, if it is only acceptable to have the list address in
the To: header and all others in the cc list then I don't know of any
command to do that.

-Mike

```

## Michael Witten, 2011-05-23 14:40

Subject: Re: [idea] separate .git dir and the working tree
Message-ID: <BANLkTinL_y8oAW2kQdyP-+CmdmrRWOrEsA@mail.gmail.com>
URL: https://gitlist.dev/e/BANLkTinL_y8oAW2kQdyP-%2BCmdmrRWOrEsA%40mail.gmail.com
In-Reply-To: <20110206004013.GB13594@mg1>

```
On Sun, Feb 6, 2011 at 00:40, Mike Gant <mike@gantsfort.com> wrote:
> So does anyone use Mutt? And do they know a recipe to move the sender
> address to the cc list? If not, I'll figure it out.

Your `To:' header should list the sender (usually what's listed in the
`From:' header); the `Cc:' header should list everything else
(including the mailing list(s) in question).

```
