Re: get upstream branch

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: get upstream branch

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:45:44

Jeff King [off-list ref] 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.

Re: get upstream branch

From: Santi Béjar <hidden>
Date: 2016-06-15 22:45:45

2008/12/9 Junio C Hamano [off-list ref]:
Jeff King [off-list ref] writes:
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help