Allowlist for .gitignore

19 points by izissise


char

you shouldn't need prefixless double-globs, gitignore will treat * as meaning "any file in any subdirectory" and then you can !/.gitignore, !*.rs, !Cargo.toml, etcetc

k749gtnc9l3w

Depedning on the project, the Con about «spurious files harder to notice» can also become «easier to forget to add a file that should be tracked»

edk-

I realise getting a large team to behave can be hard, but this is how git already works if you don't git add .. Is it really necessary to co-opt a different feature just to stop people abusing this one?

dbushell

Big fan of the allowlist approach. I stumbled upon a similar pattern using:

/*
/**/*.*

to disallow all files (with extension) and everything in root. Then allowing a directory + sub directories is easy. I typically allow files by extension like OP.

caius

Interesting idea, I've done this with .dockerignore files before (in both monorepos and app repos) to great success. Hadn't thought to do it with tracked files in git though.

ClashTheBunny

Can you, in a monorepo situation, sync this with the build and owners methods?

Anything I build is ignored, so doing a diff between when I hit build and when it exits gives me a list of files I want to throw away most of the time?

Anything that isn't owned by a specific person or team should not be in there, so exclude it. Make sure owners is also allowlist only.