# BUG: cannot remove new staged files in sparse checkout

2 messages from 2022-04-06 to 2022-04-06. Participants: Erik Cervin Edin.
Thread: https://gitlist.dev/t/57677

## Erik Cervin Edin, 2022-04-06 12:51

Subject: BUG: cannot remove new staged files in sparse checkout
Message-ID: <CA+JQ7M-Haf3R8xp-sqyJXPZza3VeaRf9uK=tyuviNFVZ0kdBTw@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BJQ7M-Haf3R8xp-sqyJXPZza3VeaRf9uK%3DtyuviNFVZ0kdBTw%40mail.gmail.com

```
Hi friends!

I've stumbled across what I believe is a bug

I've found myself with new files that are staged, not part of the
sparse-checkout, that I cannot unstage using git restore --staged, ie
  git restore --staged :\
does nothing.

I'm able to get rid of the using
  git stash && git stash drop
but intuitively I would expect restore --staged to work, even if the
files are not part of the sparse checkout

I end up in this peculiar situation by doing the following.
Having branches:
  foo/bar
  origin/foo
and then running
  git switch -c foo
Updatings files: 100% (X/X) done.
fatal: cannot lock ref 'refs/heads/foo': 'refs/heads/foo/bar' exists;
cannot create 'refs/heads/foo'

```

## Erik Cervin Edin, 2022-04-06 13:52

Subject: Re: BUG: cannot remove new staged files in sparse checkout
Message-ID: <CA+JQ7M-CNYCUAWEi42=0d6LVHZREAm7bFN=BAxA9ZWmqmZ6K7Q@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BJQ7M-CNYCUAWEi42%3D0d6LVHZREAm7bFN%3DBAxA9ZWmqmZ6K7Q%40mail.gmail.com
In-Reply-To: <CA+JQ7M-Haf3R8xp-sqyJXPZza3VeaRf9uK=tyuviNFVZ0kdBTw@mail.gmail.com>

```
I should add this behavior was seen in
  git version 2.35.1.windows.2

```
