[英]How do I get the remote tracking branch for a branch in Git?
For example, let's say master
is tracking origin/master
. 例如,假设master
正在跟踪origin/master
。 How can I ask Git to tell me that master
is tracking origin/master
in a way useful for programs? 我怎么能让Git告诉我master
正在以对程序有用的方式跟踪origin/master
?
<fill-in-the-blank> master
Since you are doing this in a script the best way is to call into the config 由于您是在脚本中执行此操作,因此最好的方法是调用配置
git config --get branch.${BRANCH}.remote
git config --get branch.${BRANCH}.merge
If you are only interested in the currently checked out branch then git provides the special reference @{u}
to refer to the current upstream. 如果您只对当前签出的分支感兴趣,那么git提供特殊引用@{u}
来引用当前上游。 Just use rev-parse
to make sure it's valid before using it. 只需使用rev-parse
确保它在使用前有效。
If you were just typing at the terminal then git branch -vv
is the way to go 如果你只是在终端输入,那么git branch -vv
就是你要走的路
The simplest way is: 最简单的方法是:
git branch -vv
which returns an output like 返回类似的输出
* master 5a24820 [origin/master] commitmsg
If you're running shell scripts and you just want the remote branch: 如果您正在运行shell脚本而您只想要远程分支:
git branch -vv | grep -oP '\[.+\]'
You could also use the following command: 您还可以使用以下命令:
git remote show origin
which displays information for your remote origin repository. 它显示远程原始存储库的信息。
eg: 例如:
Remote branch:
master tracked Local branch configured for 'git pull':
master merges with remote master
The master merges with remote master
tells you that origin\\master
is being tracked by your master branch. master merges with remote master
告诉您origin\\master
正在跟踪origin\\master
。 It's not very elegant though. 虽然它不是很优雅。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.