Git-显示远程分支的远程名称 [英] Git - show remote name of remote branch

查看:75
本文介绍了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.

这篇关于Git-显示远程分支的远程名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆