You can use sparse-checkout
to sparsly populate your working directory. sparse-checkout
makes use of the skip-worktree
bit which makes git assume that the file in your working tree is up to date no matter what.
For the following I'll assume that you are currently in the root of your repository and have a clean working tree (git stash
e.g.).
First you have to enable sparse-checkout
using git config core.sparsecheckout true
; after this you can define all patterns you want to "ignore" on checkout in .git/info/sparse-checkout
.
The syntax is the same as in a .gitignore
file, the difference being that you define all files you want to checkout not the ones you want to ignore.
Let's assume you want to avoid checking out all png
files in your repository, then your sparse-checkout
file could look like this:
* # Include everything
!*.png # Flag png files with the 'skip-worktree' bit
If you want to apply the sparse-checkout
to your current working directory you have to execute a read-tree
command afterwards.
git read-tree -m -u HEAD
After that you can continue working with your repository as usual, without the "ignored" files in your working tree.
TL;DR:
- Activate
sparse-checkout
: git config core.sparsecheckout true
- Define a
sparse-checkout
file under .git/info/
containing the patterns of files you want to include
- Update your working tree
git read-tree -m -u HEAD
You can read more on sparse-checkout
in the official documentation of git read-tree
.