Trying to make sense of git fetch

Suppose that the repo at $REPO_URL has multiple branches, including one called dev. Now, suppose I run the following commands, one right after the other

% git clone $REPO_URL --branch dev wd
% cd wd
% git branch -a
* dev
  remotes/origin/HEAD -> origin/master
  remotes/origin/dev
  remotes/origin/issue6
  remotes/origin/issue26
  remotes/origin/issue30
  ...
  remotes/origin/issue709
  remotes/origin/issue712
  remotes/origin/issue716
  remotes/origin/master

What must I do at this point so that for each branch of the form remotes/origin/X there’s a local branch X that matches it exactly? By this I mean that the following two commands would produce identical output:

  • Visual Studio 2013 with TFS online using Git: Saving files checks-in automatically
  • Is there a git personal server for sharing changes between machines?
  • How to setup gitattributes to filter part of a file?
  • Git rebase instead of merge, the correct way to do it?
  • git clone https/ssl error
  • GIT push: permission denied (public key)
  • % git rev-parse remotes/origin/X
    % git rev-parse X
    

    and also that the output of git branch -a would end up looking like this:

    * dev
      issue6
      issue26
      issue30
      ...
      issue709
      issue712
      issue716
      master
      remotes/origin/HEAD -> origin/master
      remotes/origin/dev
      remotes/origin/issue6
      remotes/origin/issue26
      remotes/origin/issue30
      ...
      remotes/origin/issue709
      remotes/origin/issue712
      remotes/origin/issue716
      remotes/origin/master
    

  • git rebase flow with code review? Possible?
  • git clone fails when uses ssh connection
  • Git doesn't save created branches
  • Using boost with VS project on Git
  • How can I change the git message of my 1 push in github?
  • Why does my git origin want to remove all my pushed changes?
  • 2 Solutions collect form web for “Trying to make sense of git fetch”

    You don’t need fetch for this, because you already did that when you cloned the repo. What you want is a local branch to match each remote tracking branch, and for this you can use checkout:

    git checkout -b issue6 origin/issue6
    

    So you can have a script that loops through all remote branches and checks them out.

    As mentioned in comments, recent versions of git can use a simpler command:

    git checkout issue6
    

    A shell for loop will do it:

    for BRANCH in $(git branch -r | grep -v HEAD) # list of remote branches (excluding HEAD)
    do
        git checkout --track ${BRANCH}
    done
    
    Git Baby is a git and github fan, let's start git clone.