tags:

views:

63

answers:

2

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?

+3  A: 

Will emit the remote being tracked:

git config branch.<branchname>.remote

Will emit the ref being tracked on that remote:

git config branch.<branchname>.merge

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:

$ git config branch.master.remote
origin
$ git config branch.master.merge
refs/heads/master
Amber
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 ignore the "refs/remotes" bit, this is exactly what was asked for.
Kevin Ballard
Nice tip Kevin. :)
Amber
+2  A: 
git config --global alias.show-upstream '!sh -c '\''

    test -n "$1" || set -- HEAD
    set -- "$(git rev-parse --symbolic-full-name "$1")"
    git for-each-ref --format="%(upstream:short)" "$1"


'\'' -'

git show_upstream
git show_upstream HEAD
git show_upstream some/local/branch
Chris Johnsen