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

Re: get upstream branch

From
SBSanti Béjar <santi@agolina.net>
Date
Dec 9, 2008, 15:51 UTC
Message-ID
<adf1fd3d0812090751r5d5a1c49k199e5e92316e0f9d@mail.gmail.com>
In-Reply-To
<7v8wqp6e89.fsf@gitster.siamese.dyndns.org>
2008/12/9 Junio C Hamano <gitster@pobox.com>:
Show 18 quoted lines
> Jeff King <peff@peff.net> writes:
>
>> In one of my scripts I do something like this (actually this is not
>> straight from my script, as the operation there is "find all pairs of
>> local/remote branches" and this is "find the current upstream"):
>>
>>   ref=`git symbolic-ref HEAD`
>>   head=${ref#refs/heads/}
>>   remote=`git config branch.$head.remote`
>>   branch=`git config branch.$head.merge`
>>   echo refs/remote/$remote/${branch#refs/heads/}
>>
>> And obviously this is missing error checking for the detached HEAD
>> (symbolic-ref should fail) and no tracking branch ($remote and/or $branch
>> will be empty) cases.
>
> Yeah, add any nonstandard layout to that set of things that are missing,
> but in practice it should not matter.
In "git pull --rebase" this is used to know the hash of the tracking branch:
        . git-parse-remote &&
        origin="$1"
        test -z "$origin" && origin=$(get_default_remote)
        reflist="$(get_remote_refs_for_fetch "$@" 2>/dev/null |
                sed "s|refs/heads/\(.*\):|\1|")" &&
        oldremoteref="$(git rev-parse -q --verify \
                "refs/remotes/$origin/$reflist")"
Santi
Previous: Junio C HamanoNext: Sverre Rabbelier
Message 5 of 7 in “get upstream branch”
  1. Jeff WhitesideDec 9, 2008
  2. Junio C HamanoDec 9, 2008
  3. Jeff KingDec 9, 2008
  4. Junio C HamanoDec 9, 2008
  5. Santi BéjarDec 9, 2008
  6. Sverre RabbelierDec 9, 2008
  7. Peter HarrisDec 9, 2008

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.