I'd like a command that emits the name of the tracked branch for the branch I'm on. Something like:
$ git checkout --track -b topic origin/master
Branch topic set up to track remote branch master from origin.
Switched to a new branch 'topic'
$ git unknown-command
origin/master
Is there such a command?
As of git 1.8.3 you can now do this:
Very convenient as it shows the tracking branch for all local branches at once, but it is not suitable for scripting.
As per Mark Longair's request, my previous comment is now reproduced as an answer.
With recent versions of git, you can emit the name of the remote-tracking branch for your current branch with
git rev-parse --symbolic-full-name @{u}
. It emits something like refs/remotes/origin/master.If you go one step further and use the
--abbrev-ref
flag, as ingit rev-parse --symbolic-full-name --abbrev-ref @{u}
, it will strip off therefs/remotes/
bit and leave you with just the short branch name, such asorigin/master
.Will emit the remote being tracked:
Will emit the ref being tracked on that remote:
I don't believe that there is a combined command that will emit both together (at least within normal Git; you could always make your own).
For example, for a local
master
branch: