The docs for git sparse-checkout
state,
By default, when running git sparse-checkout init, the root directory is added as a parent pattern. At this point, the sparse-checkout file contains the following patterns:
/* !/*/
However, I do not want to include the root in sparse-checkout
I want something like,
/directory_i_want
!/*
!/*/
But that doesn't work, returning instead
warning: unrecognized pattern:
/*
warning: disabling cone pattern matching
Such that the sparse-checkout only pulls the one directory at the top, and not ever file in the repository's root. How can I achieve this?
You are seeing that because you have enabled
sparseCheckoutCone
. From the reference:However it is not automatically enabled, so I wonder why you have it set. Anyway, you clearly cannot use it since you are excluding pretty everything except for
directory_i_want
. First of all, disable that option:Next, restore the initial repo:
And in the end, choose the pattern you need with
If you now look at the file
$GIT_DIR/info/sparse-checkout
, you will see a very simple pattern (directory_i_want/
) and that is enough. Consider that with thesparse-checkout
you tried, the order is important: you cannot putdirectory_i_want
at the start and then negate it with!/*/
. It would result in an error saying something like: