Clone/download a subdirectory of a git repository

All off topic discussions go here. Everything from the funny thing your cat did to your favorite tv shows. Non-programming computer questions are ok too.
Post Reply
User avatar
AndrewAPrice
Member
Member
Posts: 2298
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Clone/download a subdirectory of a git repository

Post by AndrewAPrice »

I'm trying to download a copy of just libc++/libc++abi from the LLVM git repo.

I was following the answer here: https://stackoverflow.com/questions/600 ... repository

Code: Select all

git init
git remote add -f origin https://github.com/llvm/llvm-project.git
git config core.sparseCheckout true
git config pull.ff only
echo "libcxx/" >> .git/info/sparse-checkout
echo "libcxxabi/" >> .git/info/sparse-checkout
git pull --depth=1 origin master
However, at 'git remote add', it tries to download nearly 1GB of data (the entire repo.)

How can I just clone/download the two subdirectories I care about?
My OS is Perception.
User avatar
iansjack
Member
Member
Posts: 4683
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Clone/download a subdirectory of a git repository

Post by iansjack »

You need to use absolute pathnames in the sparse-checkout file.

Also, have a look at this thread: https://stackoverflow.com/questions/411 ... repository

versions of git newer that 2.25.0 have a "sparse-checkout" command that makes it easier to work with sparse checkouts.

Edit: OK - having checked out that latter thread, here is the sequence of events you need:

Code: Select all

git clone --no-checkout --depth 1 git://github.com/llvm/llvm-project.git
cd llvm-project
git config core.sparsecheckout true 
echo "libcxx/*" > .git/info/sparse-checkout
echo "libcxxabi/*" >> .git/info/sparse-checkout
git checkout
This is tested, and working, on Linux. I believe that on Windows you need to omit the quotes in the echo commands, but I haven't tested this.
Post Reply