On Hacker News
.gitignore Isn't the only way to ignore files in Git
Read the full article on nelson.cloud ↗411
points
129
comments
0
notable voices
The 5-second version
- Git provides three levels of file ignoring: repository-wide .gitignore, per-repo .git/info/exclude, and global ~/.config/git/ignore.
- .gitignore is version-controlled and shared with the team, while .git/info/exclude is local to your machine and specific to a single repository.
- The global ignore file at ~/.config/git/ignore applies across all repositories on your machine and is ideal for OS-specific files like .DS_Store.
- You can customize the global ignore file location using git config --global core.excludesFile and revert with --unset.
- Use git check-ignore -v <filename> to identify which ignore rule and file is causing a specific file to be ignored.
Top voices
Verbatim comments from the thread's most notable / highest-karma participants.
kevincox14.9k karma
The global/user wide exclude is a feature that should be more widely known. I frequently have people submitting changes to add their IDE/OS/AI/... files to every project's .gitignore. They are almost always pleasantly surprised when I tell them that they can add them to their standard configuration and have them ignored everywhere without bothering every project and without risk of accidentally committing them on a project where they haven't updated the .gitignore yet. My general rule is that i…Read on HN ↗
> If a single macOS user works on ten different projects, should all ten projects add that line, Not only do people think that, they also think that every pet tool that every pet user might decide to use should also end up cluttering up .gitignores for every project on earth. Worse, these people have created whole templates for this, so they can start a new project with ignores for dozens of tools they don't even use. 9 out of 10 times, this includes a broken ignore for Vim swap files. I think…Read on HN ↗
eyelidlessness12.2k karma
I’m not sure kindness is the best framing. At least, not in terms of being nice to any particular person who might commit unwanted files by mistake. It’s one of several tools a project can use to ensure quality, alongside eg linters and formatters. Automating those (in this case by defaulting to the expected outcome) reduces friction on basically every operation anyone might do in a project, in any context. Through the lens of kindness, it benefits you as well as your team… and ultimately ever…Read on HN ↗
This is how I see it. The more contributors you have with a code base, the larger the possibility that at least one person will mistakenly commit something that could have easily been avoided by just preemptively adding it to the project .gitignore. You cant prompt every file or folder, but its almost no effort to catch the obvious ones.Read on HN ↗