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?
While “master” is the default name for a starting branch when you run git init which is the only reason it's widely used, “origin” is the default name for a remote when you run git clone . If you run git clone -o booyah instead, then you will have booyah/master as your default remote branch.
Use Status Command Your branch is up to date with 'origin/master'. The first line shows which branch are you on. The second shows your upstream branch if there are any set.
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 in git rev-parse --symbolic-full-name --abbrev-ref @{u}
, it will strip off the refs/remotes/
bit and leave you with just the short branch name, such as origin/master
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With