Settings

Theme

.gitignore Everything by Default

pliutau.com

20 points by der_gopher 4 months ago · 7 comments

Reader

flysand7 4 months 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 4 months 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.

gravel7623 3 months ago

I kinda like it, but if you come to think of it, that's just a misuse of `git add -A`. Nothing goes into a git repository unless you specifically add it, so why not just be more careful when adding files?

austinjp 4 months 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 4 months ago

You can also gitignore everything and add files with the -f flag

  • btschaegg 4 months 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 4 months 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.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection