Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>update</strong></p> <p>As pointed out by amalloy, recent versions of git support finding the matching tracking branch for a given branch by giving "branchname@{upstream}" (or "branchname@{u}", or "@{u}" for the tracking branch of HEAD). This effectively supercedes the script below. You can do:</p> <pre class="lang-sh prettyprint-override"><code>git rev-list @{u}.. git rev-list --left-right --boundary @{u}... gitk @{u}... </code></pre> <p>etc. For example, I have <code>git q</code> aliased to <code>git log --pretty='...' @{u}..</code> to show me "queued" commits ready for pushing.</p> <p><strong>original answer</strong></p> <p>There doesn't seem to be an easy way to find the tracking branch in general, without parsing lots more git config than is practical in a few shell commands. But for many cases this will go a long way:</p> <pre class="lang-sh prettyprint-override"><code># work out the current branch name currentbranch=$(expr $(git symbolic-ref HEAD) : 'refs/heads/\(.*\)') [ -n "$currentbranch" ] || die "You don't seem to be on a branch" # look up this branch in the configuration remote=$(git config branch.$currentbranch.remote) remote_ref=$(git config branch.$currentbranch.merge) # convert the remote ref into the tracking ref... this is a hack remote_branch=$(expr $remote_ref : 'refs/heads/\(.*\)') tracking_branch=refs/remotes/$remote/$remote_branch # now $tracking_branch should be the local ref tracking HEAD git rev-list $tracking_branch..HEAD </code></pre> <p>Another, more brute-force, approach:</p> <pre><code>git rev-list HEAD --not --remotes </code></pre> <p>jamessan's answer explains how to find the relative differences between $tracking_branch and HEAD using <code>git rev-list</code>. One fun thing you can do:</p> <pre><code>git rev-list --left-right $tracking_branch...HEAD </code></pre> <p>(note <em>three</em> dots between $tracking_branch and HEAD). This will show commits on both "arms" with a distinguishing mark at the front: "&lt;" for commits on $tracking_branch, and ">" for commits on HEAD.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload