Git提取未在for-each-ref中显示远程分支 [英] Git fetch does not show remote branch in for-each-ref
问题描述
我有一个远程分支 feature/test2
.我想取它.我跑:
I have a remote branch feature/test2
. I want to fetch it. I run:
git fetch origin feature/test2
然后我得到:
From <URL>
* branch feature/test2 -> FETCH_HEAD
但是当我跑步时:
git for-each-ref --format='%(refname:short)' refs/remotes/origin/feature/test2
我看不到 feature/test2
.仅当我运行 get fetch
,然后运行上面的命令时,我才会看到 feature/test2
.为什么会这样?
I don't see feature/test2
. Only if I run get fetch
, and then the command above, I'll see feature/test2
. Why is that?
推荐答案
当您获取分支时,git会更新本地的相应ref,我们将其称为远程跟踪分支.它反映了此远程引用的最后一个已知状态.
When you fetch a branch, git updates the corresponding ref in your local, which we call a remote-tracking branch. It mirrors the last known state of this remote ref.
您可以使用 git branch -r
但是这些不是您的 local 分支,您的 for-each-ref
命令要求这些分支.
But these are not your local branches, which your for-each-ref
command asks for.
-(以下假设您使用的是git版本> 1.8.3)-
要为远程 origin/feature/test2
创建本地副本,请签出
To create a local counterpart to your remote origin/feature/test2
, check it out
git checkout feature/test2
和git会将名称识别为您的远程跟踪分支的名称(因为您早先已将其提取),并设置了用于推/拉操作的链接.
and git will recognize the name as one one your remote-tracking branches (since you already fetched it earlier) and set the link for push/pull operations.
目前,它只会出现在 for-each-ref
命令的输出中.
At this point only will it appear in the output of your for-each-ref
command.
这篇关于Git提取未在for-each-ref中显示远程分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!