Git-显示远程分支的远程名称

问题描述:

是否有Git命令显示远程分支的远程名称?

Is there a Git command to show the remote name of a remote branch?

目前,我坚持使用诸如...之类的shell utils从远程分支引用中提取远程名称.

Currently I stick with extracting the remote name from a remote branch ref using shell utils like ...

$ echo "remote-name/branch-name" | sed -r 's;^([^/]+)/.*;\1;'
remote-name

有时将其通过以进行验证

sometimes passing it through for validation purposes

$ git rev-parse --symbolic-full-name "remote-name/branch-name" | ...

我想知道是否有内置命令.

I wonder if there's a builtin command like.

$ git wanted-command [wanted options] "remote-name/branch-name"
remote-name

我看过 rev-parse remote ls-remote 的联机帮助页.

I've looked though the manpages of rev-parse, remote and ls-remote.

不是最漂亮的解决方案,但我认为它通常应该可以工作.(我觉得应该有一个更好的方法,但是我暂时无法想到.)

Not the prettiest solution but I think it should generally work. (I feel like there should be a better way but I can't think of it at the moment.)

symref=$(git symbolic-ref --short HEAD)
git config --local "branch.$symref.remote"

并且,为完整起见并总结以下一些评论,可从获取远程服务器上的跟踪分支的名称(可能与本地存储库中的remote ref名称不同).branch.$ symref.merge .

And, for completeness and to sum-up some of the comments below, the name of the tracking branch on the remote (which may not be the same as the name remote ref in the local repository) is available from branch.$symref.merge.