Stop Using Git Ignore
eddiejaoude.substack.com
eddiejaoude.substack.com
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.
Yes the title is a little bit controversial
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.
it was more about stop using the repo git ignore for everything, rather than not use it at all
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?
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.
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.
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.
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.
> 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.
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.
Use the repo’s ignore, not your own.
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
> 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.
System global .gitignore solves a problem specific to that developer
Repo .gitignore solves a problem for the project (and every developer)
> 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...
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 :)
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
Easy enough to catch but you'll miss some. Literally no cost to adding it to repo config either
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.
I will look into this idea. Thanks again
Strong disagree. Please do continue trying to educate the community, but that's no reason to take the guardrails off.
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?
Many projects may want to commit IDE files. Ignoring them globally is simply wrong.
can you elaborate on why they would want to commit IDE generated files? I have only seen this in legacy projects
what happens if people want to use different IDEs?
Not an issue
> 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?
That’s fine. Nothing stopping it.
IMHO the .gitignore should be the source of truth.
"...for your personal files"
thank you, that means a lot to me! I really appreciate the feedback and support
Almost mandatory for monorepos too!
I really appreciate you adding value to the conversation, thank you!
for you and your tools, but what about everyone else?
Look at using dotfiles to sync your computer's config to multiple computers, it is a great tool
There's no reason to gatekeep what goes to the .gitignore
.git/info/excludeNot 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 :)
Some focus on battles they are likely to win, others on battles they are bound to lose.