git fetch origin doesn't fetch all branches

Cerran picture Cerran · Feb 25, 2014 · Viewed 12.6k times · Source

I read in the answers to this question that git fetch origin should fetch all branches of origin. In my case, it doesn't seem to give me any branches, though. Here's what I did:

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?

Answer

Cerran picture Cerran · Feb 25, 2014

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