# Re: .gitignore issue

3 messages from 2026-01-21 to 2026-01-21. Participants: Pushkar Singh, Jeff King, Junio C Hamano.
Thread: https://gitlist.dev/t/64846

## Pushkar Singh, 2026-01-21 18:51

Subject: Re: .gitignore issue
Message-ID: <SL2P216MB1885CE309BDBA65860D8762FA296A@SL2P216MB1885.KORP216.PROD.OUTLOOK.COM>
URL: https://gitlist.dev/e/SL2P216MB1885CE309BDBA65860D8762FA296A%40SL2P216MB1885.KORP216.PROD.OUTLOOK.COM

```
Hi Alf,

This is expected behavior.
When a directory matches an ignore rule, Git stops descending into it entirely. The pattern

        backup_STOCKS*/

matches directories starting with backup_STOCKS, and once Git prunes traversal at that level, similarly prefixed paths can disappear from git status, which is why backups/ no longer shows up.

This isn’t a bug, but a result of how ignore patterns and directory pruning work.

If you want to ignore only those directories and nothing else, anchoring the pattern helps:

        /backup_STOCKS_*/

You can also verify which rule is responsible with:

        git check-ignore -v backups/

Hope that clears it up.

Best,
Pushkar
```

## Jeff King, 2026-01-21 21:03

Subject: Re: .gitignore issue
Message-ID: <20260121210312.GA723458@coredump.intra.peff.net>
URL: https://gitlist.dev/e/20260121210312.GA723458%40coredump.intra.peff.net
In-Reply-To: <SL2P216MB1885CE309BDBA65860D8762FA296A@SL2P216MB1885.KORP216.PROD.OUTLOOK.COM>

```
On Wed, Jan 21, 2026 at 06:51:02PM +0000, Pushkar Singh wrote:

> This is expected behavior.
> When a directory matches an ignore rule, Git stops descending into it entirely. The pattern
> 
>         backup_STOCKS*/
> 
> matches directories starting with backup_STOCKS, and once Git prunes traversal at that level, similarly prefixed paths can disappear from git status, which is why backups/ no longer shows up.
> 
> This isn’t a bug, but a result of how ignore patterns and directory pruning work.

I found this explanation confusing: surely we would never match
"backups/" itself via a pattern like "backup_STOCKS*". And I'm not sure
what you mean by "similarly prefixed paths".

But what I suspect is happening here (and what you were trying to get
at) is that Git will not report an empty directory as untracked. And one
that consists only of ignored files is considered empty.

So a simpler example:

  git init
  mkdir subdir
  git status

At this point "git status" will report nothing, because there are no
files at all.

If we add a file:

  echo foo >subdir/file
  git status

Now "subdir/" is untracked (unless you use --untracked-files=all, in
which case we actually list "subdir/file" itself).

And if we ignore it like this:

  echo subdir/file >.gitignore
  git status

Now subdir/ is no longer reported. And we get the same effect with an
un-anchored top-level pattern, which also matches in subdirectories:

  echo file >.gitignore
  git status

We can't know for certain this is what's going on because Alf didn't
show us what's in the backups/ directory, but one imagines it is also
full of backup_STOCKS_* directories.

> If you want to ignore only those directories and nothing else, anchoring the pattern helps:
> 
>         /backup_STOCKS_*/
> 
> You can also verify which rule is responsible with:
> 
>         git check-ignore -v backups/

So yes, both of these are very good advice.

-Peff

```

## Junio C Hamano, 2026-01-21 21:09

Subject: Re: .gitignore issue
Message-ID: <xmqq343ysmem.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqq343ysmem.fsf%40gitster.g
In-Reply-To: <20260121210312.GA723458@coredump.intra.peff.net>

```
Jeff King <peff@peff.net> writes:

> On Wed, Jan 21, 2026 at 06:51:02PM +0000, Pushkar Singh wrote:
>
>> This is expected behavior.
>> When a directory matches an ignore rule, Git stops descending into it entirely. The pattern
>> 
>>         backup_STOCKS*/
>> 
>> matches directories starting with backup_STOCKS, and once Git prunes traversal at that level, similarly prefixed paths can disappear from git status, which is why backups/ no longer shows up.
>> 
>> This isn’t a bug, but a result of how ignore patterns and directory pruning work.
>
> I found this explanation confusing: surely we would never match
> "backups/" itself via a pattern like "backup_STOCKS*". And I'm not sure
> what you mean by "similarly prefixed paths".

Great minds think alike.  I was writing almost identical response
about backups/ being full of backups/backup_STOCKS_{1,2,3,4} and
nothing unignored in there.

> We can't know for certain this is what's going on because Alf didn't
> show us what's in the backups/ directory, but one imagines it is also
> full of backup_STOCKS_* directories.

Thanks.

```
