2

git version 2.25.1

I'm trying to clone only a specific directory from the git repository using the below command ;

git clone --depth 1 --filter=blob:none --sparse https://github.com/gitexpert/testGithub.git
cd testGithub
git sparse-checkout set banana

I'm getting this output:

hello.rb
readme.text
test.md

but the expected output should be :

I want to clone only the root folder banana not the one from the src folder.

enter image description here

also, how do I pull the local copy up-to-date with the remote repository?

4
  • 1
    git sparse-checkout set takes file name patterns that are similar to .gitignore entries, so banana means everything named banana as either a directory or a file name. You would want /banana to limit it to just the banana top level directory. Note that this (and .gitignore and .gitattributes) is one of the few places that Git considers things to be "folders-and-files" rather than just one big file name with embedded slashes. Commented May 13, 2022 at 3:18
  • 2
    In relatively recent versions of Git, git sparse-checkout has something called cone mode that makes it go faster. Your setup is a candidate for this mode. See the git sparse-checkout documentation for details. Commented May 13, 2022 at 3:19
  • 1
    Note further that --filter makes a partial clone. This is separate from sparse checkout, though combining the two can help save a lot of space in extremely large monorepos. The partial clone code is, however, not really ready for everyday use by many people. It can be extremely network-intensive and inefficient, for instance. Commented May 13, 2022 at 3:21
  • 1
    Ultimately, you're still downloading commits, not individual files. The partial clone stuff means that you're leaving your repository objects database full of "holes", as it were, that say that if and when your Git software needs some file, it can go back to GitHub and download just that one object. The current major inefficiency lies in the fact that Git fills in the "holes" one piece at a time at the moment, without any sort of sensible batching. Commented May 13, 2022 at 3:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.