Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Git have a whitelist functionality?

Tags:

git

Git has the .gitignore file which is for a blacklist on excluded files/folders.

Is there an adversary function to this? Here is my use case.

BigDir/
  DirAA/
  DirAB/
  DirAC/
  DirAD/
  DirAE/
  .....

Is there a way to just say "allow only these directories?" (a whitelist)

Maybe something like...

.gitkeep

DirAA/
DirAC/

which would result in All other directories BUT DirAA and DirAC to be ignored.

I would just add each other directory to the .gitignore but these folders keep growing, and I wouldn't want to keep adding each new folder.

like image 710
ddavison Avatar asked Jun 10 '26 10:06

ddavison


1 Answers

Per help from @amalbala's comment, this is how I can achieve what i want:

.gitignore

# first ignore everything
*

# then don't ignore the root directory
!*/

# now whitelist the particular directories and all files within them
!DirAA/*
!DirAC/*

This will result in everything being ignored, BUT DirAA/ and DirAC/.

like image 80
ddavison Avatar answered Jun 12 '26 10:06

ddavison



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!