August 18th, 2024

Stop Using Git Ignore

Eddie Jaoude advocates for using a global Git ignore file alongside project-specific ones to reduce clutter, streamline personal exclusions, and improve management practices among developers.

Read original articleLink Icon
Stop Using Git Ignore

Eddie Jaoude emphasizes the importance of using a global Git ignore file in addition to the project-specific .gitignore file. While the project .gitignore helps manage files that should not be tracked in a repository, it often becomes cluttered with entries for various IDEs and tools that differ among developers. This can lead to confusion and an ever-growing list of exclusions that may not be relevant to all contributors. Jaoude suggests that a global Git ignore file can streamline this process by allowing developers to set personal exclusions that apply across all their repositories. This approach minimizes the risk of accidentally committing unwanted files, such as system-generated files like .DS_Store on macOS. To set up a global Git ignore, users can create a .gitignore file in their home directory and configure Git to recognize it. Jaoude argues that maintainers should avoid overloading the project .gitignore with excessive entries and instead focus on educating the community about proper usage. This strategy not only simplifies the management of ignored files but also promotes better practices among developers.

- A global Git ignore file can prevent unnecessary clutter in project-specific .gitignore files.

- Developers can customize their global ignore settings to suit their individual workflows.

- Overloading the project .gitignore can lead to confusion and maintenance challenges.

- Educating the community on proper Git ignore usage benefits all contributors.

- Setting up a global Git ignore is a straightforward process that enhances productivity.

Link Icon 18 comments
By @gwynforthewyn - 6 months
Being honest, I dislike the tone of this sort of clickbaity rephrasing of the article title. The actual title is "You must use your Global Git Ignore!" which is completely true; the nuanced observation from the article "Using the git ignore feature is great but it has limitations, which is why I think this file is overused and often incorrectly" is a worthwhile hook, and presented thoughtfully.

The title "Stop Using Git Ignore", which the author of the blog post chose for this submission, doesn't represent his actual article well, though it probably gets more upvotes on Hacker News. I wish he'd presented the article more accurately, as it's a worthwhile observation that, for example, we probably have so many .DS_Store files and .vscode/.idea directories that defining them once will save us some hassle.

By @nullindividual - 6 months
You'd still need a repository .gitignore, more-so if you're not working in a professional development shop (i.e., SMB/enterprise IT) or open source project.

There don't seem to be any downsides to a long .gitignore. Who cares if it is 100 or 1000 lines?

Kind of pointless, in my view. I think a user-global .gitignore is fine to have to make sure you don't make mistakes for net-new projects or projects where someone forgot to add your exclusions, but otherwise, you're going to need both if you choose to use a user-global.

By @ghusto - 6 months
This is bad advice. The repo’s ignore file is there so that other people (without certain domain knowledge) don’t accidentally commit undesirable files, including directories containing sensitive information (which get generated by some tools like Terraform).

Use the repo’s ignore, not your own.

By @efilife - 6 months
Problems listed in the article:

> Everyone uses different operating systems, IDEs and dev tools.

How is this related to .gitignore?

> This list will only keep growing, it will never end

Where's the problem? A random Facebook's repo has its gitignore file weigh 2KB[0]. Is this a problem?

> Is the “.gitignore” file competing with the “README.md” for the most updated file in the git repo? I hope not

Again, why is this a bad thing?

The author just wanted to rant about something but didn't know about what

*[0] https://github.com/facebook/facebook-ios-sdk/blob/main/.giti...

By @wobblyasp - 6 months
I'd rather enforce it at the repo then hope and pray everyone updates their global configs.

Easy enough to catch but you'll miss some. Literally no cost to adding it to repo config either

By @vegetablepotpie - 6 months
Using a user gitignore file works if you’re responsible for your development environment. This does not work for other developers who are not responsible for their development environment.

The first place to catch errant build files and artifacts from entering the repo database is the .gitignore file. The second place to catch them is the PR. The .gitignore prevents repetitive file adds from entering the PR.

What I don’t want to see in an enterprise environment is someone checking in a 100MB binary file that gets checked into dev because the team was busy and approved a PR hastily. What would be helpful is a git hook that checks the mime type of a file and decide if it should even by a type of file that should be checked into a project.

By @default-kramer - 6 months
> As a maintainer, don’t fall into the trap of putting every possible exclusion into the repo’s git ignore. This really is a “sticky plaster” approach in my view. What we should try to do is up-skill and educate the community, so it benefits everyone in the long run.

Strong disagree. Please do continue trying to educate the community, but that's no reason to take the guardrails off.

By @forrestthewoods - 6 months
Disagree.

Many projects may want to commit IDE files. Ignoring them globally is simply wrong.

By @htk - 6 months
Let's hope that people who resort to clickbait titles never complain about dark patterns in software, because what they do is analogous, they're tricking me to their advantage.
By @TrianguloY - 6 months
Just a quick mention to remind that .gitignore files can be placed in any folder/subfolder inside a repository, and they will refer to folders inside itself only. The global .gitignore should be used for global rules and root folders, but if you have path with more than one folder on it, you may want to add it to a .gitignore inside that subfolder itself.

Almost mandatory for monorepos too!

By @kennu - 6 months
It would be very inconvenient to try to synchronize global gitignore settings to all my computers and development environments. When .gitignore files are part of the project, they are automatically distributed everywhere where they are needed.
By @hbogert - 6 months
not sure I agree with the article or not, just wanted to state there's a third option: you can define your ignore rules per project but not necessarily share the, by putting the ignore rules in:

  .git/info/exclude
By @jmclnx - 6 months
>I think most people are aware of the repo’s git ignore file

Not me, never heard of it.

I use ./.git/info/exclude to bypass commits and pushes, that is good enough for me.

Quickly reading the title, I though it was about stop using git period, go to something else :)

By @yodon - 6 months
Everyone is free to pick a proverbial hill to die on.

Some focus on battles they are likely to win, others on battles they are bound to lose.

By @dvt - 6 months
This seems like a terrible idea.. imagine framework A that has a throwaway folder called ".blah"—now imagine framework B that has a very important configuration folder called ".blah"—so at best this would only cover IDE and OS stuff. But that stuff ends up being like what, 10 lines at most?
By @Lws803 - 6 months
Ignoring .env files globally could prevent some mistakes.. :D