git fetch origin 不获取所有分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22022106/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
git fetch origin doesn't fetch all branches
提问by Cerran
I read in the answers to this questionthat git fetch origin
should fetch allbranches of origin. In my case, it doesn't seem to give me any branches, though. Here's what I did:
我读了这个问题的答案,git fetch origin
应该获取所有的起源分支。不过,就我而言,它似乎没有给我任何分支。这是我所做的:
Initially, a remote called origin had 7 branches. I cloned it. git branch
then returned only master
. I did git fetch origin
, and git branch
still only shows master
. How can I get the other 6 branches without fetching them individually?
最初,名为 origin 的远程有 7 个分支。我克隆了它。git branch
然后只返回master
。我做了git fetch origin
,git branch
仍然只显示master
。如何在不单独获取其他 6 个分支的情况下获取它们?
回答by Cerran
You have all 7 branches, but git branch
only shows local branches. Even though you now have the branch data locally on your system, they are still considered "remote branches". You can see them with git branch -a
.They'll be called something like remotes/origin/branchname
. You can check them out by specifying this full name: git checkout remotes/origin/branchname
.
您拥有所有 7 个分支,但git branch
仅显示本地分支。即使您现在在系统上本地拥有分支数据,它们仍被视为“远程分支”。您可以使用git branch -a
. 它们将被称为类似remotes/origin/branchname
. 您可以通过指定以下全名来查看它们:git checkout remotes/origin/branchname
。
Also, you already got all of these branches when you cloned the repository. Running git fetch origin
will simply update your repository with anything new that happened on origin since you last fetched (or cloned).
此外,当您克隆存储库时,您已经获得了所有这些分支。运行git fetch origin
只会使用自上次获取(或克隆)以来发生在源上的任何新内容更新您的存储库。
You can read more about remote branches in the git documentation: Git Branching - Remote Branches
您可以在 git 文档中阅读有关远程分支的更多信息:Git Branching - Remote Branches
回答by Xennex81
Although this question was answered by the question asker, here is the real deal: the reason you are getting confused is because git fetch
will show you the gory details of what it does on a newremote, but it will not show you anything (git clone) when cloning the repo at first. So cloning only creates the local master branch. Because it checks it out, by default. Checking it out creates it locally.
虽然这个问题是由提问者回答的,但这是真正的问题:你感到困惑的原因是因为它git fetch
会向你展示它在新遥控器上所做的事情的血腥细节,但它不会向你展示任何东西(git clone)首先克隆 repo 时。所以克隆只会创建本地主分支。因为默认情况下它会检查它。检查它会在本地创建它。
So basically what you need to do is what you indicated in the beginning: check out all branches individually. So basically what you get is this:
所以基本上你需要做的是你在开始时指出的:单独检查所有分支。所以基本上你得到的是这样的:
git branch -a | grep origin | sed "s@.*origin/@@" | while read f; do
git checkout $f
done
There are probably more low-level "plumbing" commands that can do it, but basically this is it from a user perspective. Actually, the answer seems to be that you can create local branches directly.
可能有更多的低级“管道”命令可以做到这一点,但从用户的角度来看,基本上就是这样。实际上,答案似乎是您可以直接创建本地分支。
git branch -a | grep origin | sed "s@.*origin/@@" | while read f; do
git branch $f origin/$f
done
But this won't set up tracking branches, probably. Answer from How to clone all remote branches in Git?
但这可能不会设置跟踪分支。来自如何在 Git 中克隆所有远程分支的回答?