# changed output in git branch -a

4 messages from 2025-06-30 to 2025-06-30. Participants: Olaf Hering, Kristoffer Haugsbakk, Junio C Hamano.
Thread: https://gitlist.dev/t/63711

## Olaf Hering, 2025-06-30 10:23

Subject: changed output in git branch -a
Message-ID: <20250630121839.6252d9d9.olaf@aepfle.de>
URL: https://gitlist.dev/e/20250630121839.6252d9d9.olaf%40aepfle.de

```
Hello,

my dumb script parses the output of "git --git-dir=some/dir/.git branch -a".
With git 2.43 it gets the expected list of "remote/branch".
With git 2.50 it also gets something like "remote/HEAD -> remote/branch".

The newer version runs on a different system. It might be that the repository
was already cloned with a different format. For some reason it does have
.git/refs/remotes/${remote}/HEAD, but the system with the older git lacks
that entry.

Is there a way to suppress such lines, or do I need to filter them manually?
There is no obvious knob mentioned in git-branch(1).


Thanks,
Olaf

```

## Kristoffer Haugsbakk, 2025-06-30 11:13

Subject: Re: changed output in git branch -a
Message-ID: <55b294bc-833d-4115-823a-2008657e68dc@app.fastmail.com>
URL: https://gitlist.dev/e/55b294bc-833d-4115-823a-2008657e68dc%40app.fastmail.com
In-Reply-To: <20250630121839.6252d9d9.olaf@aepfle.de>

```
On Mon, Jun 30, 2025, at 12:23, Olaf Hering wrote:
> Hello,
>
> my dumb script parses the output of "git --git-dir=some/dir/.git branch -a".
> With git 2.43 it gets the expected list of "remote/branch".
> With git 2.50 it also gets something like "remote/HEAD -> remote/branch".
>
> The newer version runs on a different system. It might be that the repository
> was already cloned with a different format. For some reason it does have
> .git/refs/remotes/${remote}/HEAD, but the system with the older git lacks
> that entry.
>
> Is there a way to suppress such lines, or do I need to filter them manually?
> There is no obvious knob mentioned in git-branch(1).

Can you use something like

    git for-each-ref --format='%(refname:short)' --exclude='**/HEAD'

Instead?  The output of this f-e-r command is stable.

-- 
Kristoffer Haugsbakk


```

## Junio C Hamano, 2025-06-30 13:31

Subject: Re: changed output in git branch -a
Message-ID: <xmqqsejh5pam.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqsejh5pam.fsf%40gitster.g
In-Reply-To: <20250630121839.6252d9d9.olaf@aepfle.de>

```
Olaf Hering <olaf@aepfle.de> writes:

> my dumb script parses the output of "git --git-dir=some/dir/.git branch -a".
> With git 2.43 it gets the expected list of "remote/branch".
> With git 2.50 it also gets something like "remote/HEAD -> remote/branch".
>
> The newer version runs on a different system. It might be that the repository
> was already cloned with a different format. For some reason it does have
> .git/refs/remotes/${remote}/HEAD, but the system with the older git lacks
> that entry.

I somehow do not think this is a version difference.  Assuming that
your default remote is called "origin", I suspect that you have
refs/remotes/origin/HEAD symbolic ref in the repository you use with
Git 2.50, while in the other repository you do not.  Both versions
are capable of showing that symbolic ref information.

You can try in the repository where you use Git 2.43

    $ git remote set-head origin -a
    $ git branch -a

to see if the difference indeed is coming from different versions.


> Is there a way to suppress such lines, or do I need to filter them manually?
> There is no obvious knob mentioned in git-branch(1).

Scripts should be reading "git for-each-ref" output in the first
place. Output from "git branch" is meant for human consumption and
is subject to change any time (even though in this case I suspect it
has not changed.


```

## Olaf Hering, 2025-06-30 14:19

Subject: Re: changed output in git branch -a
Message-ID: <20250630161953.3824c610.olaf@aepfle.de>
URL: https://gitlist.dev/e/20250630161953.3824c610.olaf%40aepfle.de
In-Reply-To: <xmqqsejh5pam.fsf@gitster.g>

```
Mon, 30 Jun 2025 06:31:29 -0700 Junio C Hamano <gitster@pobox.com>:

> You can try in the repository where you use Git 2.43
>     $ git remote set-head origin -a
>     $ git branch -a
> to see if the difference indeed is coming from different versions.

Thanks, it does not depend on the version. For some reason the repository
on the system with the older git had no default branch set. The repository
was cloned a long time ago, maybe default branches were never set initially.

I changed my script to use for-each-ref.


Olaf

```
