# GIT_WORK_TREE environment variable not working

3 messages from 2010-02-01 to 2010-02-01. Participants: Ron Garret, Jeff King.
Thread: https://gitlist.dev/t/22462

## Ron Garret, 2010-02-01 01:33

Subject: GIT_WORK_TREE environment variable not working
Message-ID: <ron1-8E7697.17334731012010@news.gmane.org>
URL: https://gitlist.dev/e/ron1-8E7697.17334731012010%40news.gmane.org

```
What am I doing wrong here?

[ron@mickey:~/devel/gittest]$ pwd
/Users/ron/devel/gittest
[ron@mickey:~/devel/gittest]$ git status
# On branch master
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#  git/
nothing added to commit but untracked files present (use "git add" to 
track)
[ron@mickey:~/devel/gittest]$ cd
[ron@mickey:~]$ export GIT_WORK_TREE=/Users/ron/devel/gittest
[ron@mickey:~]$ git status
fatal: Not a git repository (or any of the parent directories): .git
[ron@mickey:~]$ git status --work-tree=/Users/ron/devel/gittest
fatal: Not a git repository (or any of the parent directories): .git
[ron@mickey:~]$

```

## Jeff King, 2010-02-01 05:19

Subject: Re: GIT_WORK_TREE environment variable not working
Message-ID: <20100201051942.GA7761@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20100201051942.GA7761%40coredump.intra.peff.net
In-Reply-To: <ron1-8E7697.17334731012010@news.gmane.org>

```
On Sun, Jan 31, 2010 at 05:33:47PM -0800, Ron Garret wrote:

> What am I doing wrong here?
> 
> [ron@mickey:~/devel/gittest]$ pwd
> /Users/ron/devel/gittest
> [ron@mickey:~/devel/gittest]$ git status
> # On branch master
> # Untracked files:
> #   (use "git add <file>..." to include in what will be committed)
> #
> #  git/
> nothing added to commit but untracked files present (use "git add" to 
> track)
> [ron@mickey:~/devel/gittest]$ cd
> [ron@mickey:~]$ export GIT_WORK_TREE=/Users/ron/devel/gittest
> [ron@mickey:~]$ git status
> fatal: Not a git repository (or any of the parent directories): .git
> [ron@mickey:~]$ git status --work-tree=/Users/ron/devel/gittest
> fatal: Not a git repository (or any of the parent directories): .git
> [ron@mickey:~]$

You haven't told git where to find the repository itself. GIT_WORK_TREE
is about saying "here are my work tree files", but it is explicitly not
about "here is where my .git directory is". That lets you keep the two
in totally separate locations. E.g., you could do something like
tracking /etc, but keep your .git directory in /var.

For your case above, you would want to also

  export GIT_DIR=/Users/ron/devel/gittest/.git

though since you have a fully formed repository, I don't think there is
really any advantage over just doing:

  cd /Users/ron/devel/gittest && git $whatever

though perhaps that is because this is not a real use case, but rather
just you trying to figure out the feature. :)

-Peff

```

## Ron Garret, 2010-02-01 07:09

Subject: Re: GIT_WORK_TREE environment variable not working
Message-ID: <ron1-EF4205.23092531012010@news.gmane.org>
URL: https://gitlist.dev/e/ron1-EF4205.23092531012010%40news.gmane.org
In-Reply-To: <20100201051942.GA7761@coredump.intra.peff.net>

```
In article <20100201051942.GA7761@coredump.intra.peff.net>,
 Jeff King <peff@peff.net> wrote:

> On Sun, Jan 31, 2010 at 05:33:47PM -0800, Ron Garret wrote:
> 
> > What am I doing wrong here?
> > 
> > [ron@mickey:~/devel/gittest]$ pwd
> > /Users/ron/devel/gittest
> > [ron@mickey:~/devel/gittest]$ git status
> > # On branch master
> > # Untracked files:
> > #   (use "git add <file>..." to include in what will be committed)
> > #
> > #  git/
> > nothing added to commit but untracked files present (use "git add" to 
> > track)
> > [ron@mickey:~/devel/gittest]$ cd
> > [ron@mickey:~]$ export GIT_WORK_TREE=/Users/ron/devel/gittest
> > [ron@mickey:~]$ git status
> > fatal: Not a git repository (or any of the parent directories): .git
> > [ron@mickey:~]$ git status --work-tree=/Users/ron/devel/gittest
> > fatal: Not a git repository (or any of the parent directories): .git
> > [ron@mickey:~]$
> 
> You haven't told git where to find the repository itself. GIT_WORK_TREE
> is about saying "here are my work tree files", but it is explicitly not
> about "here is where my .git directory is". That lets you keep the two
> in totally separate locations. E.g., you could do something like
> tracking /etc, but keep your .git directory in /var.
> 
> For your case above, you would want to also
> 
>   export GIT_DIR=/Users/ron/devel/gittest/.git

Ah.  Thanks!

> though since you have a fully formed repository, I don't think there is
> really any advantage over just doing:
> 
>   cd /Users/ron/devel/gittest && git $whatever
> 
> though perhaps that is because this is not a real use case, but rather
> just you trying to figure out the feature. :)

It's a real use case.  The situation is that I'm using git as a back end 
for an IDE, so I can't rely on the cwd.

rg

```
