# question re: git show-ref and matching ref patterns from the front

3 messages from 2021-04-11 to 2021-04-11. Participants: Chris Jerdonek, brian m. carlson.
Thread: https://gitlist.dev/t/55474

## Chris Jerdonek, 2021-04-11 01:24

Subject: question re: git show-ref and matching ref patterns from the front
Message-ID: <CAOTb1wef2w_H4mwMMwR4En8665GduAMoceL45+OYC4DSBPtozQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAOTb1wef2w_H4mwMMwR4En8665GduAMoceL45%2BOYC4DSBPtozQ%40mail.gmail.com

```
Hi, I noticed that git-show-ref only seems to permit matching patterns
from the end of a ref name:
https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt-ltpatterngt82308203
For example, "git show-ref master" will include both
"refs/heads/master" and "refs/remotes/origin/master".

However, is there a way to limit Git to showing refs starting with a
prefix, and that doesn't also require Git to iterate over all refs?

It seems like that would be natural and useful e.g. for repos with
many refs and/or repos with namespaces. Am I missing something, or
would that be a useful addition?

Thanks,
--Chris

```

## brian m. carlson, 2021-04-11 01:54

Subject: Re: question re: git show-ref and matching ref patterns from the front
Message-ID: <YHJW4xCgw6GN0Rag@camp.crustytoothpaste.net>
URL: https://gitlist.dev/e/YHJW4xCgw6GN0Rag%40camp.crustytoothpaste.net
In-Reply-To: <CAOTb1wef2w_H4mwMMwR4En8665GduAMoceL45+OYC4DSBPtozQ@mail.gmail.com>

```
On 2021-04-11 at 01:24:57, Chris Jerdonek wrote:
> Hi, I noticed that git-show-ref only seems to permit matching patterns
> from the end of a ref name:
> https://git-scm.com/docs/git-show-ref#Documentation/git-show-ref.txt-ltpatterngt82308203
> For example, "git show-ref master" will include both
> "refs/heads/master" and "refs/remotes/origin/master".
> 
> However, is there a way to limit Git to showing refs starting with a
> prefix, and that doesn't also require Git to iterate over all refs?
> 
> It seems like that would be natural and useful e.g. for repos with
> many refs and/or repos with namespaces. Am I missing something, or
> would that be a useful addition?

I believe you can do this with git for-each-ref.  It accepts prefixes,
and assuming you don't use a case-insensitive comparison, it will
restrict itself to iterating over only those prefixes you specify, not
all refs.
-- 
brian m. carlson (he/him or they/them)
Houston, Texas, US

```

## Chris Jerdonek, 2021-04-11 02:09

Subject: Re: question re: git show-ref and matching ref patterns from the front
Message-ID: <CAOTb1wftqhQSZ8KRyh0hXBE7enM8KG85H-UyxBObnsx8Ff8vvA@mail.gmail.com>
URL: https://gitlist.dev/e/CAOTb1wftqhQSZ8KRyh0hXBE7enM8KG85H-UyxBObnsx8Ff8vvA%40mail.gmail.com
In-Reply-To: <YHJW4xCgw6GN0Rag@camp.crustytoothpaste.net>

```
On Sat, Apr 10, 2021 at 6:54 PM brian m. carlson
<sandals@crustytoothpaste.net> wrote:
>
> On 2021-04-11 at 01:24:57, Chris Jerdonek wrote:
> > However, is there a way to limit Git to showing refs starting with a
> > prefix, and that doesn't also require Git to iterate over all refs?
>
> I believe you can do this with git for-each-ref.  It accepts prefixes,
> and assuming you don't use a case-insensitive comparison, it will
> restrict itself to iterating over only those prefixes you specify, not
> all refs.

Thanks. One minor difference, though, seems to be that git
for-each-ref doesn't support including the HEAD ref, which you can do
with git-show-ref by passing ---head.

--Chris

```
