git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Feature request: git status --branch-only

From
Ondra Medek <xmedeko@gmail.com>
Date
Nov 14, 2023, 19:44 UTC
Message-ID
<CAJsoDaG71Jrt=M7iTn8zTvevv5FA4iuDjd2otDNy4tS5RCyX-w@mail.gmail.com>
In-Reply-To
<00033c86-dbd7-4c88-bfbd-8f6766cd66c9@gmail.com>
Hi Phillip,

even "[gone]" would not be much of help for me. I would need something like "origin/master [gone]" i.e. what "git status -b --porcelain" prints. (Note, I've written about "git status -b --porcelain=v2" before because v2 is better documented and parseable.)

Regards Ondra Medek

On Tue, 14 Nov 2023 at 16:02, Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 69 quoted lines
>
> Hi Ondra
>
> On 14/11/2023 12:40, Ondra Medek wrote:
> > Hi Phillip,
> >
> > it does not work for a fresh clone of an empty repository
> >
> >      git for-each-ref --format="%(upstream:short)" refs/heads/master
> >
> > outputs nothing, while
>
> Oh dear, that's a shame. I wonder if it is a bug because the
> documentation says that
>
>         --format="%(upstream:track)"
>
> should print "[gone]" whenever an unknown upstream ref is encountered
> but trying that on a clone of an empty repository gives no output.
>
> Best Wishes
>
> Phillip
>
>
> >      git status -b --no-ahead-behind --porcelain=v2
> >
> > outputs
> >
> > # branch.oid (initial)
> > # branch.head master
> > # branch.upstream origin/master
> >
> > I.e. it outputs a proper upstream branch.
> >
> > Best regards
> > Ondra
> >
> > Ondra Medek
> >
> >
> > On Tue, 14 Nov 2023 at 13:28, Phillip Wood <phillip.wood123@gmail.com> wrote:
> >>
> >> Hi Ondra
> >>
> >> On 14/11/2023 10:16, Ondra Medek wrote:
> >>> Hello,
> >>> I am working on a tol which should fetch changes from a remote
> >>> repository on a user click. I want to limit fetch on the current
> >>> remote tracking branch (something like "origin/master"), but
> >>> surprisingly, it's hard to get it for all corner cases like a fresh
> >>> clone of an empty repository or detached head, etc. E.g see this SO
> >>> thread https://stackoverflow.com/questions/171550/find-out-which-remote-branch-a-local-branch-is-tracking/52896538
> >>
> >> I think you can do this by calling
> >>
> >>          git symbolic-ref --quiet HEAD
> >>
> >> to get the full refname of the current branch. If HEAD is detached it
> >> will print nothing and exit with exit code 1. Then you can call
> >>
> >>          git for-each-ref --format="%(upstream:short)" $refname
> >>
> >> to get the upstream branch
> >>
> >> Best Wishes
> >>
> >> Phillip
> >
Previous: Phillip WoodNext: Jeff King
Message 5 of 7 in “Feature request: git status --branch-only”
  1. Ondra MedekNov 14, 2023
  2. Phillip WoodNov 14, 2023
  3. Ondra MedekNov 14, 2023
  4. Phillip WoodNov 14, 2023
  5. Ondra MedekNov 14, 2023
  6. Jeff KingNov 14, 2023
  7. phillip.wood123@gmail.comNov 16, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.