I am aware that a very similar question has been asked before, but not only is the provided answer awful and doesn't answer the question, but it seems there is no consensus about the technique as well. And even after searching on the net in general there doesn't seem to be any solution that works.
So here is it again.
How to configure git sparse-checkout so that it checks out the entire repository, with the exception of a particular (top level) directory?
Directory is called Tests_NR in the example.
Please provide an example that works with git version >= 2.37.3, on Windows Server 2016.
If possible, it should not be required to checkout the entire repo beforehand. (And then remove the excluded dir).
But rather suppose we start with a clone without working directory. (git clone <url> --no-checkout
)
What I have tried:
Create a file named ignore.txt
that contains:
/*
!/Tests_NR/
Then
> git sparse-checkout init
> type ignore.txt | git sparse-checkout set --stdin
> git sparse-checkout list
!/Tests_NR
*
> git checkout master
=> Did not work. The working dir only contains the top level files, and not any directory.
Update
Following @phd' s comment, this works for me in a Windows Powershell prompt:
> git sparse-checkout init
> git sparse-checkout set '/*' '!/Tests_NR/'
> git sparse-checkout list
/*
!/Tests_NR/
The following git checkout will effectively get everything except Tests_NR.
Be careful, that when used in a regular Windows cmd, this yields a different result and fails:
>git sparse-checkout init
>git sparse-checkout set '/*' '!/Tests_NR/'
>git sparse-checkout list
'/*'
'!/Tests_NR/'