Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I track only specific files using .gitignore? [duplicate]

Tags:

git

gitignore

What should I put in my Git repository's .gitignore to exclude all files and directories there except specific ones. For example if I have a large number of files and directories in a repo, and just want Git to track fileX, .fileY, and directoryZ, but completely ignore everything else, what should be in my .gitignore?

like image 620
orome Avatar asked Apr 08 '26 09:04

orome


1 Answers

You should ignore content; but exclude folders.
That allows you to exclude files.

/**
!/**/
!fileX

That is because:

It is not possible to re-include a file if a parent directory of that file is excluded.

Check the effect of a .gitignore with git checkignore -v

git check-ignore -v -- afile
like image 187
VonC Avatar answered Apr 10 '26 23:04

VonC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!