Search code examples
jgit

Is partial checkout supported by JGit 3.7?


I am using Jgit 3.7 for importing files from Git repository. But I would like to import only set of folders instead of all. I know Git supports this, but I would like to know Jgit 3.7 supports the same? If so, can someone guide me.


Solution

  • By design, a cloned git repository always contains all files and folders of the original repository.

    With native git, you can create a shallow clone (git clone --depth 1 ...) but this feature is not yet implemented in JGit. EDIT 2023-06-13: As of version 6.3 JGit supports shallow fetch and clone.

    Contradicting its general design, native git (since version 1.7) lets you create partial clones with sparse checkouts but this is also not possible out-of-the-box in JGit.

    What you can do in JGit though - once you have cloned a repository - is to checkout only some files of a branch or commit.

    git.checkout().setStartPoint("some-branch").addPath("path/to/file").call()