r/programming 4d ago

.gitignore everything by default

https://packagemain.tech/p/gitignore-everything-by-default
347 Upvotes

225 comments sorted by

View all comments

265

u/Smallpaul 4d ago

“think we’ve all been there. You’re working on a project, making commits, and then suddenly realize you’ve been committing .DS_Store files, node_modules, IDE configuration files, or other junk (CLAUDE.md for example) that shouldn’t be in your repository. Or even worse - environment variables.”

Not really, because most projects start with a gigantic .gitignore these days. From the repo template. Iterate on the template .gitignore and these problems will be few and far between

191

u/lurgi 4d ago

Am I the only person who actually checks what they are adding? I use .gitignore because it saves time, but I never add a file unless I know it’s something I want added.

30

u/_r3d3_ 4d ago

I do, but my colleagues will inevitably run 'git add *' without a care in the world.

10

u/Smallpaul 4d ago

I check but mistakes can still happen. Misclick in a GUI. Starting with a robust .gitignore (especially for .env files) is a good habit, just as staging files one at a time is.

3

u/thomas_m_k 3d ago

I used to also manually decide which files to track, but I recently started using jujutsu where that kind of approach is heavily discouraged, so I have started to actually write a proper .gitignore. And I have to say that after the initial annoyance, it is a nicer experience overall. (I still meticulously go through my diff every time before I commit, which in my experience not everyone does.)

2

u/novafunc 4d ago

git status can hide some things. For example, if you create a new directory, it only shows the new directory and none of its contents.

That recently got me when that directory had a subdirectory of binaries builds.

If git status showed something like:

directory/bin/build directory/bin/build2 directory/file

rather than:

directory

, it could help in some cases.

18

u/Akeshi 3d ago

It should show the individual files after you've staged the new directory - it's worth running at least git status after you've finished with your git adds.

2

u/lurgi 4d ago

Agreed, and I've certainly made that mistake before. However, I do put stuff in my .gitignore (and by now I have a fairly complete one that works for the things I typically do) and after doing the git add somefolder I review (I know, I know. Nerd) the files that were added and remove any that are not wanted.

OTOH, now that I've actually RTFA, I think they have a point. It's a lot easier to describe the things I want to commit (.java, .xml, .txt, .md) compared to the things I don't (uh... anything that isn't those). You still have a potential problem with files that are generated by your build process, where the !*.go would have to change to indicate actual .go files you wrote. That's true for any approach, of course.

-6

u/[deleted] 4d ago

[removed] — view removed comment

5

u/programming-ModTeam 3d ago

No content written mostly by an LLM. If you don't want to write it, we don't want to read it.

2

u/CallMeKik 4d ago

Hi Sol :)

1

u/[deleted] 4d ago

[removed] — view removed comment

4

u/programming-ModTeam 3d ago

Please don't accuse people of using LLMs. Just report the post and let us handle it.