Now, what better to do when you find a problem than SOLVE IT?? Indeed dear readers, so I hunted down the code, forked the project from Github, and started trying to add a flag for "block" vs "allow" locally. Part of the setup was
npm install which generates a local directory
node_modules/, full of libraries that you most definitely (probably, except in weird cases, I guess) do not want to track in Git. Generally this would be accomlished by having a row in the project's
.gitignore, telling Git not to worry about anything in
node_modules/, so that when you do
git status it doesn't say that everything in
node_modules is untracked, or when you do
git add . it doesn't try to add anything in
node_modules, etc. But the
.gitignore for this project (which existed! that was my first question) mysteriously did not contain any mention of
node_modules. Had previous contributors, including the main creator/maintainer, all just quietly and carefully ignored it themselves in their brains?
Idk, I'm not a mind reader (as much as I sometimes try to be). Being the helpful human I am though, I made a pull request to add
node_modules to the project's
.gitignore. Now, here is where the plot thickens! The maintainer replied to me (very kindly, I must add - I opened a pile of PRs and issues at the same time and the maintainer was very patient with me 😉) to explain that, while they agree that
node_modules should not be committed, I should actually have it in my global git config to ignore it everywhere. "Best practice!" they said. (Though not actually quite like that, alone as a sentence or with an explanation mark. That is me taking liberties with the editing.) Wow! I thought. I had never heard of such a concept, to centralize things like a python ENV or node_modules to a global .gitignore.
So I searched the internet high and low for "best practices on global vs project gitignores". Just kidding, I searched for 2 minutes′ , before realizing the internet in general was not going to offer trustworthy answers and I had better find a true source of truth, which ended up being
man gitignore. The relevant lines are there for you to investigate. The section I wanted was about "Which file to place a pattern in", and the most important sections were the first and third ("other repositories" means other developers local copies of the same project):
* Patterns which should be version-controlled and distributed to
other repositories via clone (i.e., files that all developers will want
to ignore) should go into a `.gitignore` file.
* Patterns which a user wants Git to
ignore in all situations (e.g., backup or temporary files generated by
the user's editor of choice) generally go into a file specified by
`core.excludesFile` in the user's `~/.gitconfig`. Its default value is
$XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or
empty, $HOME/.config/git/ignore is used instead.
I had a real hard time with the first sentence. My problem was interpreting "patterns" to mean "the actual files represented by the patterns". So I thought it meant "Files which should be version-controlled ..(ie, those that all developers will want to ignore)..." which is utterly contradictory. Either you want them version controlled, or you want them ignored. You can't have it both ways people! I thought maybe they forgot a "n't" at the end of "should". I went on a long voyage reading about how to contribute to git using the mailing list so that I could fix the manpage, before eventually realizing that when it says "Patterns which should be ....", "Pattern" literally means the actual plaintext word in the .gitignore file and not the file itself. -__-
- text editor-specific or operating system-specific files go in global git config to ignore
- project (and therefore language)-specific files go in project
.gitignoreto be committed and shared with fellow devs working on the same project
Cool beans kiddie winks, thanks for hanging around! Also, make sure you know what you're talking about before emailing the whole mailing list of git. Heh, that would have been awkward.
Also, can you tell I figured out how to make REAL FOOTNOTES?! Very cool. So much better than my haphazard asterisks system. I might have to go through old posts and fix them up. 😃 ↩︎