OSDev.org
https://forum.osdev.org/

Clone/download a subdirectory of a git repository
https://forum.osdev.org/viewtopic.php?f=11&t=36764
Page 1 of 1

Author:  AndrewAPrice [ Fri May 15, 2020 4:09 pm ]
Post subject:  Clone/download a subdirectory of a git repository

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/600079/how-do-i-clone-a-subdirectory-only-of-a-git-repository

Code:
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?

Author:  iansjack [ Fri May 15, 2020 11:45 pm ]
Post subject:  Re: Clone/download a subdirectory of a git repository

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:
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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/