3

Does git clone create a copy of every single source file/version on your local machine, for all branches?

Or does it just copy master, and all of the branches are just references? (and when you checkout a branch it downloads commits for that branch?)

Basically I'm wondering if I have the source from 100 different branches on my machine when i really only want a small handful.

Thanks.

Aaron
  • 652
  • 4
  • 10

2 Answers2

3

It does get the full history of the remote repository.

What it doesn't get is the config and the hooks (they are not clone, pulled or pushed).

It also doesn't create a local branch for each of the remote branches cloned.
That is why if you are cloning your clone (two clones in a row), you will end up with only one branch.
As mentioned in git clone

  • Clones a repository into a newly created directory,
  • creates remote-tracking branches for each branch in the cloned repository (visible using git branch -r), and
  • creates and checks out an initial branch that is forked from the cloned repository's currently active branch.
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the info. So does creation of remote-tracking branches mean that the actual code is on my laptop too? Or is it meta-data, and the actual code gets downloaded if I checkout the remote branch? Sorry for being slow - there's something that's not quite clicked despite reading the docs, and I'm struggling to articulate it. – Aaron Dec 10 '13 at 11:39
  • @Aaron the actual code is in your `.git` repo. When you checkout a branch, you are updating your local working directory with code from your local `.git` repo. Everything is local. You can unplug your wifi connection entirely. Until the time you will push back, everything happens locally. – VonC Dec 10 '13 at 11:49
  • Ok, gottit thanks. I guess it just feels unintuitive that the entire repository (as far as source files) exists on my local machine, when I'm only ever going to be interested in 2 or 3 branches out of the whole lot. – Aaron Dec 10 '13 at 12:01
  • @Aaron But that is the very nature of *Distributed* Version Control System for you: see http://stackoverflow.com/q/2704996/6309 and http://stackoverflow.com/a/2563917/6309 – VonC Dec 10 '13 at 12:03
1

Short answer is that after the clone, you have all the files from the master branch, but have the full repository locally. This means you do not have to network access to checkout a different branch.

cforbish
  • 8,567
  • 3
  • 28
  • 32