2

(note - My git version is 1.8.3.)

Say I checkout branch master of an example project.

git clone --branch master "//server/GitProject.git" "C:/Project"

The repository got cloned. But...what EXACTLY has been cloned? To me, it seems that everything got cloned. The whole project tree, all branches. The "--branch master" only creates local branch "master", sets a tracking to origin/master and makes HEAD pointing at master.

But there are like 50 different branches, each with hundreds, maybe thousands of commits. I don't know (and I don't care) what most of these branches are for, some of them represent different and obsolete old versions, some were created by different teams, different team members. Sure, this may also mean that our company's project & branch management got kind of out of control but let's just assume we can't do anything about that.

Now, after the checkout, the output of git branch -a outputs something like this.

*master
remotes/origin/Branch1
remotes/origin/Branch2
remotes/origin/Branch3
remotes/origin/Branch4
...etc

Data of the recent master have something like 371 MB ... but the .git directory has 2 GB.

Now let's asssume I'm the only person in the company who's commiting to master. I don't need the whole project tree. I'll try to remove all other branches to keep only the relevant data.

If I remove all the remote branches I don't need LOCALLY like this...(unfortunately, I haven't found a command for it)

git branch -rd origin/Branch1
git branch -rd origin/Branch2
git branch -rd origin/Branch3
git branch -rd origin/Branch4
...
git gc --prune=now

...the size of .git folder reduces from 2 GB to 477 MB. This suggests that git checkout really downloaded the whole commit tree, not just the part pointing to the branch I wanted.

Everything works fine now. Pull and push commands works only with master, when I specify it.

First question: Is "relevant data only" workflow even sensible with git? If not, why?

If answer to the first question is yes, then there is a second problem I have.

Sometimes, I need to work with a different branch that may be anywhere in the commit tree. But I haven't figured out how to do it correctly.

If i call git remote show origin, I get something like this

* remote origin
Fetch URL: //server/GitProject.git
Push  URL: C:\Project
HEAD branch: master
Remote branches:
  Branch1                 new (next fetch will store in remotes/origin)
  Branch2                 new (next fetch will store in remotes/origin)
  Branch3                 new (next fetch will store in remotes/origin)
  etc...

I see git can reach branches, whose commits, references and tracking branches I don't have locally.

But this sentence "next fetch will store in remotes/origin" puzzles me. I know that if I git fetch I get my remote branch Branch1 locally created - but together with everything else, with the whole commit tree of the project. Size of the .git folder will again increase to 2 GB. And I don't want to do that. That branch I want may just consists of few commits forked from recent master.

Second question: How do I download ONLY a specific branch when I don't have the local reference to the remote branch and in a way that will download only the relevant part of the commit tree?

I tried this...

git fetch origin Branch1

...which seems to do exactly what I want. But when I git branch -a, this is the output. There is no Branch1.

* master remotes/origin/HEAD -> origin/master remotes/origin/master

I guess this means that the commits for Branch1 got downloaded and appended to the tree (or probably not appended at all?) but since there was no local reference matching the remote branch, there is no way to reach it. So I have to create the local reference...somehow. I think. But I'm not sure how.

Community
  • 1
  • 1
Mirek
  • 4,013
  • 2
  • 32
  • 47
  • That's how git works. If you don't want to have the whole repository but only a particular revision - consider using svn instead. – zerkms Jun 25 '14 at 12:00

0 Answers0