This question is essentially the opposite of this one.
There are certain files that exist for reasons on the team\'s remote. They are not frequently changed
The sparse-checkout should work.
Enable sparse-checkout:
git config core.sparsecheckout true
Create the config file .git/info/sparse-checkout
and input the patterns:
*
!path/to/file1/you/want/to/delete
!path/to/file2/you/want/to/delete
!path/to/file3/you/want/to/delete
The patterns mean "to checkout everything(*) except(!) the rest paths".
Make it work:
git checkout
This way, these files are not checked out and everything is the same to you as long as you don't need to modify or checkout these files. In case you need these files to be checked out, remove or comment the file paths in .git/info/sparse-checkout
and leave only *
, and run git checkout
again to checkout the hidden files.
You can try:
git update-index --assume-unchanged -- unWantedFile
rm unWantedFile
# work
# ...
# later on
git update-index --no-assume-unchanged -- unWantedFile
git restore unWantedFile
That should be enough to work in a working tree without that file, while telling Git the file is still there.
It works too with git update-index --skip-worktree -- unWantedFile
.
I have written about the difference between the two here.