From: Junio C Hamano Date: Tue, 09 Dec 2008 06:43:02 GMT Subject: Re: get upstream branch Message-ID: <7v8wqp6e89.fsf@gitster.siamese.dyndns.org> In-Reply-To: <20081209055629.GB2972@coredump.intra.peff.net> Jeff King 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.