# --work-tree does not work for git-stash

2 messages from 2017-09-11 to 2017-09-11. Participants: Allen Li.
Thread: https://gitlist.dev/t/46736

## Allen Li, 2017-09-11 18:32

Subject: --work-tree does not work for git-stash
Message-ID: <CAJr1M6eS0jY22=0nvV41uDybcHUdjBv8CgRhHmBNFM=Z0J9YCA@mail.gmail.com>
URL: https://gitlist.dev/e/CAJr1M6eS0jY22%3D0nvV41uDybcHUdjBv8CgRhHmBNFM%3DZ0J9YCA%40mail.gmail.com

```
$ git --version
git version 2.14.1.581

This does not work:

$ git --git-dir ~/foo/.git --work-tree ~/foo stash create
fatal: /usr/lib/git-core/git-stash cannot be used without a working tree.

This does:

$ git --git-dir ~/foo/.git --work-tree ~/foo -C ~/foo stash create

I found a description of the bug here:

https://stackoverflow.com/a/5863555

```

## Allen Li, 2017-09-11 18:59

Subject: Re: --work-tree does not work for git-stash
Message-ID: <CAJr1M6eXDiAEmaen+w5PCBLpSL1+=6RmyA=zgHuKV=aYbrRcdg@mail.gmail.com>
URL: https://gitlist.dev/e/CAJr1M6eXDiAEmaen%2Bw5PCBLpSL1%2B%3D6RmyA%3DzgHuKV%3DaYbrRcdg%40mail.gmail.com
In-Reply-To: <CAJr1M6eS0jY22=0nvV41uDybcHUdjBv8CgRhHmBNFM=Z0J9YCA@mail.gmail.com>

```
On Mon, Sep 11, 2017 at 11:32 AM, Allen Li <vianchielfaura@gmail.com> wrote:
> $ git --version
> git version 2.14.1.581
>
> This does not work:
>
> $ git --git-dir ~/foo/.git --work-tree ~/foo stash create
> fatal: /usr/lib/git-core/git-stash cannot be used without a working tree.
>
> This does:
>
> $ git --git-dir ~/foo/.git --work-tree ~/foo -C ~/foo stash create
>
> I found a description of the bug here:
>
> https://stackoverflow.com/a/5863555

I think that this bug may be quite serious.

If you were to run:

$ git --git-dir ~/tmp/.git stash

This will actually stash using your current directory as the worktree,
which could potentially screw up things quite seriously.  In my case,
I had an unstaged file at ~/tmp/tmp, so Git decided to remove the
entire ~/tmp directory as my current directory was ~ and I have a git
repo in ~ for my dotfiles.

```
