0

I'm fairly new to Git and am trying to a grip on what's going on behind the scenes!

Given a remote repository with these branches:

  • master
  • feature 1
  • feature 2

If I git clone this repository and then type git branch -a only master is available locally and feature 1 and feature 2 are listed as remote branches.

My understanding is that as a distributed version control system I have all the commits locally, therefore I should have access to all the branches. Given that's the case, why can't I just swap between branches locally? Is this something to do with references/labels?

What haven't I understood?! :D

Pseudonymous
  • 839
  • 5
  • 13
  • 3
    AFAIK it's just the branch references that are missing. You do have all the commits locally. – Holloway Jun 18 '15 at 08:58
  • 1
    Duplicate: https://stackoverflow.com/questions/67699/clone-all-remote-branches-with-git – Arkanosis Jun 18 '15 at 08:59
  • So it is the case I have all the commits that make up all the branches. And I also have references saying something like "the remote calls commit X 'feature 1'". But I don't have references which say "you call commit X 'feature 1'". And this is what I need in order to checkout a working copy? – Pseudonymous Jun 18 '15 at 09:06
  • 1
    Noteworthy: the accepted answer in the question referenced by Arkanosis doesn't give you the "why" you're asking for. An answer by Cerran further down in that question entitled ' "Why you only see "master" ' explains the why. – Mr Grok Jun 18 '15 at 09:07

2 Answers2

2

You have all data after clone locally. But by default only master branch tracked remote master branch. You can checkout to other branch without problems. To track other remote branch use -u option for fetch command.

Gauthier
  • 40,309
  • 11
  • 63
  • 97
gomons
  • 1,946
  • 14
  • 25
1

This answer to a similar question gives the "why" you are after. +1 @Arkanosis for the initial link (not a duplicate question but the answer to this question does lie in that one)

Community
  • 1
  • 1
Mr Grok
  • 3,876
  • 5
  • 31
  • 40