I discovered this[0] "allowlist" approach for Go a while ago:
# Ignore everything \* # But not these files... !/.gitignore !*.go !go.sum !go.mod !README.md !LICENSE # ...even if they are in subdirectories !*/