.gitignore Everything by Default

19 der_gopher 6 9/4/2025, 2:09:16 PM pliutau.com ↗

Comments (6)

flysand7 · 1d ago
There's something similar I've done programming on linux. I've been working on some things in Odin programming language for a while and there are a ton of changes I've made where the commit contained an executable, because when Odin compiler makes the executable it names it after the main package's directory, without suffix.

Once I complained about this to the community someone suggested a clever gitignore hack:

    *
    !*/
    !*.*
This by default ignores all files, except those that have a suffix and directories. I think this is a useful lesson - if you flip which files you ignore you can change the failure mode from "I accidentally committed a huge file into a repo" to "why isn't it working?". The latter can be pretty much be answered by good CI testing (maybe not always though).
thomascountz · 14h ago
Instead of ignoring everything, this is how I manage my $HOME directory of dotfiles via a bare git repo.

  $ alias config='/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME'
  $ echo ".cfg" >> ~/.gitignore
  $ git clone --bare <git-repo-url> $HOME/.cfg
  $ config config --local status.showUntrackedFiles no

Nothing is shown as untracked by default. When I add new config files to track, I have to add them to stage them explicitly.

The only sticking point is when I forget to use `git add -u .` when committing changes to files which are already being tracked.

I don't remember why I went with this over the global * ignore.

austinjp · 13h ago
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
  !*/

[0] https://github.com/github/gitignore/blob/main/community/Gola...
Cloudef · 1d ago
You can also gitignore everything and add files with the -f flag
btschaegg · 1d ago
This.

I just learned this recently. Intuitively, I had assumed that I could .gitignore a file and have it not show up in `git status`, even after staging it with `git add -f` and committing it this way.

Turns out: That's not how it works. Instead, the .gitignore entries simply don't count for any already tracked files.

(Yes, I know about `git update-index --assume-unchanged` but that has its own set of drawbacks…)

Noumenon72 · 1d ago
This is a smart pattern with .dockerignore where it keeps a lot of huge things from getting copied into the context... but it's also so confusing every time your container doesn't have the new file you created.

I think you're going to have to allow `app/*` which means you will be checking in some .DS_STORE files anyway.