1

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?

itgeek
  • 549
  • 1
  • 15
  • 33
  • 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. – torek May 13 '22 at 03:18
  • 1
    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](https://git-scm.com/docs/git-sparse-checkout) for details. – torek May 13 '22 at 03: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. – torek May 13 '22 at 03: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. – torek May 13 '22 at 03:24

0 Answers0