# Query for certain branches, but not the rest

2 messages from 2012-11-25 to 2012-11-28. Participants: Felipe Contreras, Jeff King.
Thread: https://gitlist.dev/t/32190

## Felipe Contreras, 2012-11-25 09:24

Subject: Query for certain branches, but not the rest
Message-ID: <CAMP44s02=E3imOv00dwyXR13nQdo1XeZTjJb_y0EVQoyYMEcQw@mail.gmail.com>
URL: https://gitlist.dev/e/CAMP44s02%3DE3imOv00dwyXR13nQdo1XeZTjJb_y0EVQoyYMEcQw%40mail.gmail.com

```
Hi,

Suppose I have these branches:

  fc/feature-a
  fc/feature-b
  master
  next

I want to show this: fc/feature-a fc/feature-b ^master ^next. I can do
'git log --branches=fc' to show the branches that begin with fc/, but
there's no way to specify the rest. If they were under a prefix, I
could do '--not --branches=prefix', but they are not.

Anybody knows a way to query branches that don't have any prefix?

It appears this works:

% git for-each-ref refs/heads/*

But I would like something parsable by rev-parse.

Any ideas?

Cheers.

-- 
Felipe Contreras

```

## Jeff King, 2012-11-28 01:57

Subject: Re: Query for certain branches, but not the rest
Message-ID: <20121128015714.GB23776@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20121128015714.GB23776%40sigill.intra.peff.net
In-Reply-To: <CAMP44s02=E3imOv00dwyXR13nQdo1XeZTjJb_y0EVQoyYMEcQw@mail.gmail.com>

```
On Sun, Nov 25, 2012 at 10:24:59AM +0100, Felipe Contreras wrote:

> Suppose I have these branches:
> 
>   fc/feature-a
>   fc/feature-b
>   master
>   next
> 
> I want to show this: fc/feature-a fc/feature-b ^master ^next. I can do
> 'git log --branches=fc' to show the branches that begin with fc/, but
> there's no way to specify the rest. If they were under a prefix, I
> could do '--not --branches=prefix', but they are not.
> 
> Anybody knows a way to query branches that don't have any prefix?

I don't think there is a way. `--branches` can take a pattern (and there
is always `--glob`), but we do not pass FNM_PATHNAME to fnmatch, so "*"
will match across `/` boundaries.

You are stuck with:

  git log --branches=fc --not $(
    git for-each-ref --format='%(refname:short)' refs/heads |
    grep -v /
  )

which is at least robust due to the restrictions on refnames (i.e., no
whitespace).

As an aside, I noticed that:

  git log --branches=does-not-exist

will see that we matched no refs and fall back to showing HEAD. That
seems a bit surprising to me.

-Peff

```
