9

I am trying to sparse-checkout a subdirectory from my git repository.

The repository contains multiple plugins for wordpress and I want to check them out one by one. With the below posted solutions I have encountered the problem that EVERYTIME I check out the parent directory of the subdirectory is also checked out and the plugins are not working.

I tried something like this Is it possible to do a sparse checkout without checking out the whole repository first? and something like that Git sparse checkout for simple web deployment .

I really hope somebody can help me because I just feel like I kind of missed some information.

Thank you.

5
  • You said you tried to follow those other answers. Did they work? Did they not work? What happened? Commented Feb 24, 2016 at 18:34
  • They did not work. I just wanted to checkout the subdirectory without any parent directories, so I set the options in the sparse-checkout file like suggested in the links I posted. What happened was, that when I wanted to checkout for example subdirectory 2 from the following structure: [Parent] > [subdirectory 1], [subdirectory 2] the parent folder was checked out also and I couldn't use it in the wordpress plugins folder. Commented Feb 27, 2016 at 10:51
  • See also: stackoverflow.com/questions/600079/… Commented Nov 14, 2019 at 17:17
  • So finally were you able to checkout subdirectory without its parent directory, I am also stuck in same problem. Please help me if you have found the solution Commented Dec 1, 2020 at 12:59
  • See this answer; stackoverflow.com/a/52269934/371, key parameter was having --no-cone when setting the path to avoid getting parent files. Commented Apr 15, 2024 at 0:25

1 Answer 1

3

The OP referenced (in 2016) the 2010 question "Is it possible to do a sparse checkout without checking out the whole repository first?", which has now a more recent (2023) answer by Kirow, using git clone --no-checkout --depth=1 --filter=blob:none.

The comments also references How do I clone a subdirectory only of a Git repository?'s answer from Ciro Santilli, using git sparse-checkout set --no-cone

I have tested the combination of both answers, with:

git clone --no-checkout --depth=1 --filter=tree:0 https://github.com/charmbracelet/lipgloss cd lipgloss git sparse-checkout set --no-cone "examples/layout/" git read-tree -m -u HEAD 

Note the git read-tree -m -u HEAD that I used in "Git sparse checkout with exclusion".

Sign up to request clarification or add additional context in comments.

2 Comments

Let me also recommend the full-handroll version of this dance.
@jthill creating a new branch, committing changes to the subdirectory, and merging with the upstream branch while maintaining the sparse checkout, … I see. A bit beyond the scope of the OP, but useful nonetheless.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.