threads / discuss / 63711

changed output in git branch -a

Subject: changed output in git branch -a

## tl;dr

4 messages between Jun 30, 2025 and Jun 30, 2025.

replies: 3people: 3as markdown or json

Olaf Hering· Jun 30, 2025, 10:23 UTC · lore
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· Jun 30, 2025, 11:13 UTC · re: Olaf Hering · lore

Re: changed output in git branch -a

On Mon, Jun 30, 2025, at 12:23, Olaf Hering wrote:
Show 13 quoted lines
> 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· Jun 30, 2025, 13:31 UTC · re: Olaf Hering · lore

Re: changed output in git branch -a

Olaf Hering <olaf@aepfle.de> writes:
Show 8 quoted lines
> 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· Jun 30, 2025, 14:19 UTC · re: Junio C Hamano · lore

Re: changed output in git branch -a

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

← back to recent threads