You can use sparse-checkout
to cut your working directory. sparse-checkout
uses the skip-worktree
, which allows git to assume that the file in the working tree is updated no matter what.
In the following cases, I assume that you are currently in the root directory of your repository and have a clean working tree ( git stash
for example.).
First you need to enable sparse-checkout
with git config core.sparsecheckout true
; after that you can define all the templates that you want to βignoreβ when placing an order in .git/info/sparse-checkout
.
The syntax is the same as in the .gitignore
file, the difference is that you define all the files that you want to check , not the ones you want to ignore.
Suppose you want to avoid checking all png
files in your repository, then your sparse-checkout
file might look like this:
*
If you want to apply sparse-checkout
to the current working directory, you must run the read-tree
command.
git read-tree -m -u HEAD
After that, you can continue to work with your repository, as usual, without the "ignored" files in the working tree.
TL DR:
- Activate
sparse-checkout
: git config core.sparsecheckout true
- Define the
sparse-checkout
file in .git/info/
containing the file templates you want to include - Update working tree
git read-tree -m -u HEAD
More information about sparse-checkout
can be found in the official git read-tree
documentation.
source share