git fetch origin doesn't fetch all branches

淺唱寂寞╮ 提交于 2019-12-04 00:40:25

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.

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).

You can read more about remote branches in the git documentation: Git Branching - Remote Branches

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 new remote, 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.

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?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!