How to fetch all remote branch, "git fetch --all" doesn't work

git branch only displays local branches. git branch -r will display remote branches, as you've seen for yourself.

git branch
*master

git branch -r
origin/master
origin/A

git fetch --all will update the list you see when you type git branch -r but it will not create the corresponding local branches.

What you want to do is checkout the branches. This will make a local copy of the remote branch and set the upstream to the remote.

git checkout -b mylocal origin/A

git branch
master
*mylocal

git branch -r
origin/master
origin/A

mylocal in this case is origin/A. The -b parameter will create the branch if it doesn't exist. You could also just type: git checkout A will will auto-name the new branch.


You need to create the fetched branch locally as well:

git fetch --all && git checkout A

I think what you're really looking for is the git branch -a command. It will show all local and remote branches. Here's an example:

# Only show local branches
$ git branch
* master
  develop

# Only show remote branches
$ git branch -r
  origin/HEAD -> origin/master
  origin/master
  origin/develop
  origin/foo

# Show both local and remote branches
$ git branch -a
* master
  develop
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/develop
  remotes/origin/foo

You will notice that all of the branches are there - the command will show both local and remote branches.

The foo branch only exits on the remote, I don't have a local foo branch. To create a local foo branch, I would use the checkout command:

# Create a local 'foo' branch from the remote one
$ git checkout foo
Branch foo set up to track remote branch foo from origin.
Switched to a new branch 'foo'

# Show both local and remote branches
$ git branch -a
* foo
  master
  develop
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/develop
  remotes/origin/foo

This should explain what you're seeing locally.