title: Get the name of local branches tracking a given remote branch
body: <p>I am trying to find which local branch would have been the default when cloning a git repository.</p>
  
  <p>In this particular context I am able to assume the remote is called <code>origin</code>. I can get the default branch for <code>origin</code> using <code>git symbolic-ref refs/remotes/origin/HEAD</code>. This returns something like <code>refs/remotes/origin/develop</code>.</p>
  
  <p>I now need to find which local branches are set up to track <code>origin/develop</code>. Obviously it's almost certainly going to be <code>develop</code>, so I could just do some string manipulation to replace <code>remotes/origin/</code> and end up with <code>refs/heads/develop</code>. However, I would like to avoid making that assumption.</p>
  
  <p>I'm currently grepping it out of the result of <code>git branch -vv</code> (specifically <code>git rev-parse --symbolic-full-name $(git branch -vv | grep "\[$(git rev-parse --abbrev-ref $(git symbolic-ref refs/remotes/origin/HEAD))\]" | awk '{print $1}')</code>). However, this is very brittle, especially as the branch name can appear in the commit message.</p>
  
  <p>I am currently using git 2.18, though could upgrade if newer verisons have a feature required to make this better.</p>