Clone a git repository without checking out the whole repo - sparse checkout procedure?

947 views Asked by At

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 
0

There are 0 answers