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

Re: Testing for existence of a remote branch from a script

From
Torsten Bögershausen <tboegi@web.de>
Date
Jan 6, 2025, 06:51 UTC
Message-ID
<20250106065121.GA8844@tb-raspi4>
In-Reply-To
<CAFOYHZDQs-mftqLQn5HiFgBWcFN6Z-WDscJt=zVLRyGTo36=HQ@mail.gmail.com>
On Mon, Jan 06, 2025 at 05:40:36PM +1300, Chris Packham wrote:
Show 23 quoted lines
> Hi,
>
> I look after some scripts we use at $dayjob for pushing changes though
> our review system.
>
> For some of our repositories we operate a triangular workflow where
> changes are fetched from one branch (e.g. 'foo') but are pushed to a
> different one ('foo_incoming'). Our CI system runs to test the changes
> and when they pass 'foo_incoming' is merged (fast-forward most of the
> time) into 'foo'.
>
> The problem I have is not all our projects use this workflow so I've
> tried to automate the detection of this. My script does something like
>
>   br=$(git rev-parse --symbolic-full-name
> refs/remotes/origin/foo_incoming -- 2>/dev/null || echo
> refs/remotes/origin/foo)
>
> The '--' is necessary because if foo_incoming doesn't exist then there
> is extra output on stdout that puts off users. But when foo_incoming
> does exist then br gets set to `refs/remotes/origin/foo_incoming\n--`.
>
> Is there a better way of checking for the existence of a remote branch?

I may have missed something, would that work: git fetch -p git branch -r

Previous: Chris PackhamNext: Junio C Hamano
Message 2 of 7 in “Testing for existence of a remote branch from a script”
  1. Chris PackhamJan 6, 2025
  2. Torsten BögershausenJan 6, 2025
  3. Junio C HamanoJan 6, 2025
  4. Theodore Ts'oJan 6, 2025
  5. Junio C HamanoJan 6, 2025
  6. Chris PackhamJan 6, 2025
  7. Theodore Ts'oJan 6, 2025

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.