How to use git sparse-checkout with multiple matching patterns

41 Views Asked by At

I'm using git sparse-checkout to have only the files I'm interested in on disk. I'm unable to figure out how to match multiple patterns.

git sparse-checkout set --no-cone "**/*.tf"

Checkout all .tf files

git sparse-checkout set --no-cone "**/*.tf.json"

Checkout all .tf.json files

How can I checkout all files that fit both patterns at once? I've tried

git sparse-checkout set --no-cone "**/*.tf **/*.tf.json"
git sparse-checkout set --no-cone "**/*.tf,**/*.tf.json"
git sparse-checkout set --no-cone "**/*.tf\n**/*.tf.json"

But none of these options match either pattern

1

There are 1 best solutions below

0
BeetleJuice On

I had misread the docs. Each pattern is a new argument, so the following works

git sparse-checkout set --no-cone "**/*.tf" "**/*.tf.json"

From the docs on set:

Write a set of patterns to the sparse-checkout file, as given as a list of arguments following the set subcommand.