# GIT_WORK_TREE; a recipe for disaster

2 messages from 2020-03-03 to 2020-03-03. Participants: Phillip Susi, Philip Oakley.
Thread: https://gitlist.dev/t/52929

## Phillip Susi, 2020-03-03 13:53

Subject: GIT_WORK_TREE; a recipe for disaster
Message-ID: <875zflh7dw.fsf@vps.thesusis.net>
URL: https://gitlist.dev/e/875zflh7dw.fsf%40vps.thesusis.net

```
I'm using git for windows version 2.25.0.windows.1.  Yesterday I was in
a bash command line and changed directories to another project.  I ran
git status and it complained about basically everything being deleted
when the files were sitting there just fine.  I thought that maybe it is
confused since I upgraded git recently and so I ran git checkout -f and
git clean -xfd to make sure that the working directory would be restored
to a pristine state.  I later changed back to the first project
directory where I was horrified to see that all of the files from the
second project had been checked out, and the changes in that project
that I had been working on for a few days had been deleted.

It seems the cause of this is that I had opened git bash from the git
gui menu instead of from the windows explorer menu.  In previous
releases, this cause GIT_DIR to be set ( I believe ), and so that
session of git bash was tied to that repoistory even if you changed
directories to another repository.  I always thought this was rather
annoying, but things seem to be worse now that I have upgraded, because
git now uses the index and hisotry log etc from the cwd, but compares
that index to files elsewhere.  This seems like a recipe for disaster.
Why does git gui set these environment variables at all, and could it
please stop?


```

## Philip Oakley, 2020-03-03 14:22

Subject: Re: GIT_WORK_TREE; a recipe for disaster
Message-ID: <c2cf7919-8a24-0b62-3f99-03bf50dcc659@iee.email>
URL: https://gitlist.dev/e/c2cf7919-8a24-0b62-3f99-03bf50dcc659%40iee.email
In-Reply-To: <875zflh7dw.fsf@vps.thesusis.net>

```
On 03/03/2020 13:53, Phillip Susi wrote:
> I'm using git for windows version 2.25.0.windows.1.  Yesterday I was in
> a bash command line and changed directories to another project.  I ran
> git status and it complained about basically everything being deleted
> when the files were sitting there just fine.  I thought that maybe it is
> confused since I upgraded git recently and so I ran git checkout -f and
> git clean -xfd to make sure that the working directory would be restored
> to a pristine state.  I later changed back to the first project
> directory where I was horrified to see that all of the files from the
> second project had been checked out, and the changes in that project
> that I had been working on for a few days had been deleted.
>
> It seems the cause of this is that I had opened git bash from the git
> gui menu instead of from the windows explorer menu.  In previous
> releases, this cause GIT_DIR to be set ( I believe ), and so that
> session of git bash was tied to that repoistory even if you changed
> directories to another repository.  I always thought this was rather
> annoying, but things seem to be worse now that I have upgraded, because
> git now uses the index and hisotry log etc from the cwd, but compares
> that index to files elsewhere.  This seems like a recipe for disaster.
> Why does git gui set these environment variables at all, and could it
> please stop?
>
Probably worth including Pratyush Yadav for the git-gui maintenance aspect.
--
Philip

```
