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.
It’s more than “a little bit controversial”, it _is_ clickbait. If your title was more true to the article’s actual premise, I doubt you’d have as much engagement. The title made me click immediately because “wow that’s a wild opinion!” I opened the article and was greeted with a much more nuanced view than I was led to believe and tbh I likely wouldn’t have read it if the title was more accurate.
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.
Yeah, the article's point is also that you need both:
> The contents of the repo’s git ignore is for the project only files and folders. Developers can customise their own global git ignore with extra exclusions they need.
The two gitignores are for different purposes. The user-specific gitignore (~/.gitignore, or ~/.config/git/ignore) is tailored to the developer's specific workflow and preferred tools, so for example, a Vim user would have different rules from an Emacs or VSCode user.
The project-level gitignore(s) are for build products. For example, if the project's build scripts create a "build" directory for all the build products, "build/" would probably be in the project's .gitignore.
It doesn't make sense to put editor-specific stuff in the project's .gitignore because the editor or IDE a contributor chooses to use to develop the project is orthogonal to the code in the project.
> It doesn't make sense to put editor-specific stuff in the project's .gitignore because the editor or IDE a contributor chooses to use to develop the project is orthogonal to the code in the project.
Why not? What's the harm?
There seems to be zero significant downsides to include editor or operating system-specific patterns in the project .gitignore. A long .gitignore doesn't cause performance issues.
To wit, you'll ultimately have someone without a global .gitignore that will lead to PR cleanup (or worse, direct commits).
The project level .gitignore prevents mistakes by all committers. This is superior to trusting a developer correctly set up their own .gitignore.
I think this is getting to the level of "optimization" because it feels good rather than doing any true good.
I'm not sure about that. We had a new hire once add a ton of .DS_Store files because we forgot to ignore it at the repo level and they didn't have a global ignore set up. I don't see the point of committing files that have no purpose in the repo, especially these ones, that could change between users age potentially polluting the diffs. We added it to the ignore list and removed the files
I don't think that's a good argument. An inexperienced developer can inadvertently do a lot of damage in infinitely many ways, and your example is just one of them. I don't think it's a good principle to structure a code base to protect inexperienced coders from themselves, which is always going to be a losing battle.
This may have been a missed opportunity for a teachable moment:
- The new hire most likely used `git commit -a` without checking `git status` or `git diff`, which is bad practice.
- The new hire probably didn't even know about their global .gitignore.
IMO a better way to steer new developers in the right direction is simply code review, and I'd think even a pretty cursory review would have caught those .DS_Store files.
We can do both those things and also take away their ability to add unwanted files which is exactly what we did. Why even allow things like this to happen when a single line to a gitignore solves it forever? The reason we saw those .DS_Store files in the first place was during PR review
Or you could have taught them how to add the ignore file on their computer so they won't be making the same mistake in any other repo or other projects…
And you could have used the opportunity to teach them about using a version control altogether and how it they aren't supposed to just throw git commit -am "fix stuff" at every problem!
The fact that they committed the .DS_store files shows there's a much deeper problem with how this employee works that something you can work around with a .gitignore file. Now the problem has just been hidden under the rug.
We don't care if this problem is "hidden under the rug". We didn't even consider it to be a problem. One line added to the gitignore and no future hires will have the ability to do this. Why is adding lines to a gitignore a problem? We've looked at it maybe a handful of times since it was initialised
You'll think about this discussion the next time it happens again on a nez git repo you've just created.
Why is adding a .gitignore line a problem you ask, but then someone could ask why is committing those .DS_store files a problem in the first place… In both cases the problem is that you are adding garbage unrelated to the project.
Committing stuff to the repo means work for other people (namely the reviewers).
And to find the answer to “why is it a problem that there's a .sublimetext line in the .gitignore” then ask yourself the question “why is it a problem if there's a .sublimetext file committed to the repository”. Why even bothering to add it to the .gitignore when you can just commit the file?
Why do you think the second scenario is an issue and not the first?
Because a dev's IDE project file can differ between every other dev, so committing it doesn't make sense. On the other hand, adding it to the .gitignore solves the problem of having differing config files.
But why is a “config file” (which is usually no more than a few dozen bytes) a problem? If you agree to add the name of the file in your .gitignore, why do you even bother to ignore it in the first place. It pollutes the .gitignore file as much as it pollutes the root directory…
The first issue helps to prevent the second issue.
Many projects will need to have a .gitignore to ignore build files or package artifacts. Adding to an existing file is preferable to adding additional files.
Adding IDE level configs can override config files for other developers. The .gitignore does not have this negative impact on others.
How can any coder or engineer or admin or tech of any stripe ask such a question?
The problem is not that babies will die.
Yet just because no babies will die and we can afford the disk space and it doesn't slow down the performance does not mean there is no reason.
What's the problem in placing 50,000 redundant copies of 2,000 lines of config in every individual repo? Where to begin?
1 - my project has a particular kind of file I need to ignore. I either have to add it to the bottom of this huge file blindly, or I have to search the file every time before adding something, in case it's already in there somewhere.
2 - my project is mysteriously not working as expected because I didn't realize that somewhere in the huge mass of everyone else's ignores in the world that MY project has in it, there are some patterns that affect files I didn't expect or ask for and didn't realize I would have to specially override.
3 - the idea doesn't scale because the world is big and essentially every file name pattern needs to be ignored by someone somewhere, so if all possible ignores were copied to every repo, every file would be ignored in every repo. In that case we should not have gitignore, we should have gitinclude. If you think the answer to this is "just pick the common things" then you just broke your own theory that everything should be copied to all.
4 - If every repo has it's own copy of the database of all ignores, then every repo has it's own out of sync copy.
If it doesn't matter that it goes out of sync, then it doesn't matter if it's in there at all in the first place. If it does matter, then how is it kept up to date?
I have edited the stock initial copy with the stuff that's particular to my project. Shall we have git itself always doing a little side git operation just on this file against a central public reference every time? So every git add/status/commit etc aside from looking at the local and origin, also checks a special origin just for that file, so that I get a patch that updates my gitignore without simply replacing it?
Maybe we split gitignore into 2 parts, a shared common global part and a project-specific part? Wow, what a great idea, why didn't git already work that way by default all along?
5 - Why stop at just one stupid copy of a database of stuff that doesn't apply per repo? If there is no harm in a redundant out of sync copy per repo, then there is no harm in a redundant out of sync copy per directory. "what's the problem?" Seriously what is the problem? Because it is the same exact answer for the repo as for the directory.
This question is ridiculous unless you are new and have never tried to use any tools yet and are still unaware of even the most basic engineering principles in general, about anything not just git or software development.
In that case, that is fair and everyone starts out as a child that has to find out everything the first time somehow. In that case the answer is "go ahead and see how it goes" because for some things if you don't understand the problem just by thinking about it and projecting implications for about 2 seconds, then no mere explaination will be convincing. Nothing I've said here was convincing right? You will just have to find out by being stupid for a while and actually run into all the little paper cuts in order to recognize that they exist and they suck and what the totally simple and obvious ways to avoid them are.
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).
Exactly, sometimes it takes me some minutes of research to determine whether a certain file should be ignored or not. In that situation, it's very appropriate to put that in the repo's gitignore, preferably with comments explaining why the pattern is included/excluded.
I don't think you read the article, there is a video at the end if you prefer.
Yes we should use git ignore for the repo specific items, so if the repo has terraform it should ignore generated files - but not desktop tools people use as we all use different dev tools
> Examples of folders included in the git ignore file are generated files like “.next” from NextJS or “test-results” from Playwright. These will be generated for every developer on the project regardless of their OS, IDE etc.
> Yes I am saying this is wrong… (let me know if you agree/disagree below)
I didn't realize that the first paragraph is saying "This is good"; I thought the second paragraph was saying that the first paragraph is bad.
I don't like to rant, I like to have professional discussions.
Than you for reading the article and for sharing the FB link with a git ignore example - the contents of the example file is not long because it doesn't have every dev tool possible, so I think you proved my point - so thank you :)
>> Everyone uses different operating systems, IDEs and dev tools.
> How is this related to .gitignore?
Exactly! I explained in the article (and video) people fill the repo git ignore with all their personal tools that generate files, for example .DS_Store, .Idea etc. This should go in their personal global git ignore
>> 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?
Have a look at some other projects. I explained in the article (and video) the file can be pages long with every possible combination and will only keep growing as new dev tools come out
>> 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?
As I explained in the article, it becomes a lot of work for the maintainers, to review, check for duplicate entries etc
yes as an open source maintainer, this is a difficult decision I need to make for each project. On one hand, I want to do the right thing, but on the other, the initial convenience does come into play - but this can come back to bite us later when people play the green square game on the git ignore file in the GitHub repo
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.
thank you for your detailed replied. The Git hook is an interesting idea, I use Git Husky for git hooks, and checking the mime type could be good to avoid files like screenshots being committed
> 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.
Thank you for reading and commenting. It is great to understand different people's perspectives.
From my experience the main downside of keeping the "guardrails on", people are less likely to learn about the importance of git global ignore and also with open source projects there can be a green square chasing game (which we also need to educate people on) - just thinking about this, more Pull Requests will come in with unwanted files though, which will be painful for contributors and maintainers, but could be a good lesson?
You've mentioned the "green square game" a lot, and I don't see how this is a problem. If someone makes a PR that is nothing but the .gitignore file, you can just reject it in one second. (Unless it is a well-researched and well-justified change, in which case you can gratefully merge it.)
I think as a solo maintainer on a project and getting many github notifications (and DMs about the notification) for their PRs every day, it had a negative effect on me.
IDE-specific files aren't necessarily auto-generated. They might include project-specific configs (random examples that come to mind include linter configs, tab/space indent settings, C library include paths)
> why they would want to commit IDE generated files
You added the word generated.
Many Windows-oriented projects a Visual Studio .sln file. This is great! You can open the sln, build, and run. It “just works”. Very nice. I wish more projects did this.
> what happens if people want to use different IDEs?
Once they're committed into the repository, they're no longer ignored, so what's the problem? The IDE files being listed in a hypothetical developer's global .gitignore do no harm in this case.
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.
Thank you for the reply. I believe you have interesting enough material to not need to resort to controversial titles. Keep writing, it'll only get better.
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.
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.
I don't understand why people make an issue of that. Just add everything that needs to be ignored to the .gitignore, as long as it makes sense to someone. If I use XYZ-Obscure-Unknown-Editor, just let me add `.xyz-obscure-unknown-editor/` to the .gitignore. It literally has no negative impact on anyone.
There's no reason to gatekeep what goes to the .gitignore
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:
Interesting to hear about your workflow! Someone else mentioned "./.git/info/exclude". It is something I will look in to and ask around to see who else uses it. Thanks for your comment
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?
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.