3

I need access to a small number of directories in a git repository that is 250 GB. Obviously checking out the whole thing is a big hit in time and disk space. I cannot, however, find a working solution to how to get only the desired directories. I can clone the whole thing and then enable sparse checkout, but that defeats the whole point.

I realize this has been asked a number of times:

How do I clone a subdirectory only of a Git repository? Is it possible to do a sparse checkout without checking out the whole repository first?

but none of these (or other: http://jasonkarns.com/blog/subdirectory-checkouts-with-git-sparse-checkout/) solutions work for me.

I'm running git 2.9.3 on a Fedora 25 machine. I've tried the following to start, but I end up with the whole repo. Changing the -f to -n for the last line has no effect.

mkdir <repo>
cd <repo>
git init
git remote add -f origin <url>

I've also tried this to no avail:

mkdir myrepo
cd myrepo  
git init
git config core.sparseCheckout true
git remote add -f origin git://...   #at this point, the whole repo comes down
echo "path/within_repo/to/desired_subdir/*" > .git/info/sparse-checkout
git checkout [branchname] # ex: master

(The same thing happens even if I execute the echo line before the git remote add line.)

Surely there is an easy solution for this that actually works, no?

EDIT: Just for completeness, this is what I'm doing now based on comments. Still have the same problem.

mkdir myrepo
cd myrepo  
git init
git config core.sparseCheckout true
echo "path/within_repo/to/desired_subdir/*" > .git/info/sparse-checkout
git remote add origin git://...   

git pull  #at this point, the whole repo comes down 
Community
  • 1
  • 1
KirkD-CO
  • 1,603
  • 1
  • 22
  • 35
  • The only thing I see here that is different from the tutorial is you are doing a checkout instead of a pull, try doing git pull origin master... – The Pax Bisonica Dec 20 '16 at 20:24
  • Thanks for the comment. It is at the 5th step in my list that the whole repo is downloaded I tried setting up the sparse-checkout file before git remote add... but that also did not work. (I edited the question to reflect this comment.) – KirkD-CO Dec 20 '16 at 21:20
  • Don't add the `-f` on your `git remote add`. Instead, try pulling after the sparse checkout is done. Your remote will be set up, like a URL, but the fetch/pull can be done afterwards. It should respect the sparse checkout. – Larry B. Dec 20 '16 at 22:03
  • Sparse checkout is only about checkout. You cannot clone only the part that you are interested in. You can clone shallowly, but that still downloads at least one commit and a complete tree. – j6t Dec 20 '16 at 22:35
  • I'm sure my git nomenclature needs to be improved - I'll work on that. My understanding is that checkout is for moving between branches of a cloned repo. Is that correct? From all this so far, it seems I'm not able to do what I want without pulling down the full repo. – KirkD-CO Dec 20 '16 at 22:40

0 Answers0