Live data from Hacker News

.gitignore Everything by Default

packagemain.tech

61–70 of 185 posts

Re: .gitignore Everything by Default

#61
post #30

- or you could stop scratching your head so hard and actually use the gitignore templates for every programming language officially recommended by github itself - https://github.com/github/gitignore - funny how I did not see a single comment talk about this

Because it's insufficient? https://github.com/github/gitignore/blob/main/Rust.gitignore for example still falls victim to basically all of the issues specifically called out.

I use alint [0][1] to define and enforce rules about files/globs that should or shouldn't be committed, among other things. You can configure it run as a pre-commit hook or in CI.

(disclaimer - this is my own tool)

[0] https://github.com/asamarts/alint

[1] https://alint.org/docs/rules/git-hygiene/git_no_denied_paths...

Re: .gitignore Everything by Default

#62
post #10

This seems like bad advice. I've very rarely committed extra files by accident, but I would 100% forget to unignore files I meant to commit. If you're doing an initial setup step to gitignore everything, why not just do an initial setup step to gitignore the usual files? Make a template that you copy into all of your repos.

Recovery from forgetting to add something is _much_ easier than recovery from adding some weird configuration file with plaintext private keys in it.

I usually have *secret in .gitignore and append .secret to any files with secrets.

Re: .gitignore Everything by Default

#63

It is weird that quite a few developers comes up with advices where they seem to come from a world where they work alone, have not work with enough people, or with enough projects. In this case, a `.gitignore_global` takes care of the usual suspects that he mentioned `.DS_Store files, IDE config, compressed files, etc.`. Even if something goes wrong, it is usually caught during the initial scaffold before critical fi…

Wow, thanks so much for . gitignore_global.

Finally can have Emacs files ignored automatically in all projects. <3

Re: .gitignore Everything by Default

#64
post #14
post #4

I don’t ignore by default, but only stage the items I explicitly want. I can’t tell you how many times I’ve been pairing with someone when they just say “git add .”, I’m always confused by that choice. I get it, but I’ve seen more problems arise from adding all than being consistently selective. To each their own.

I use "git add ." (or rather -A), but I will always do a "git status" first to make sure I'm not doing something silly. Of course you still have to be careful about subdirectories, which is why I usually also do a "git status" again before committing.

git add . is nondestructive and reversible. I tend to do git add . and then run git status.

I’m far more interested in confirming my mental model of what I am about to commit if I git commit right now than my mental model of what will be added if I git add right now.

If I didn’t already have that muscle memory I might try to switch to git add -v . which would tell me what files it added. I’d argue that a sane git would just output git status after a git add operation.

But also a sane git would have a more logical command than git rm —cached to unstage a file. Like git unstage perhaps.

Re: .gitignore Everything by Default

#65
I think the article starts out correct, but as soon as it recommends letting through `*.go` it becomes mistaken.

I'd say the correct approach is to include all your top level files (i.e. CMakeLists.txt, .gitignore, etc.) but also your top-level *directories*, i.e. `/renderer`, `/UI`, `/tools`, whatever.

Then, crucially, your build system must also prohibit in-source builds and require a dedicated build directory.

This way, it's presumed that everything in your source tree is pristine and correct, and can host a variety of file types depending on your needs (realistically, source trees can contain lots of things; data, json, images, text, etc.) while you also shouldn't have to worry about polluting it accidentally.

Re: .gitignore Everything by Default

#66
post #10

This seems like bad advice. I've very rarely committed extra files by accident, but I would 100% forget to unignore files I meant to commit. If you're doing an initial setup step to gitignore everything, why not just do an initial setup step to gitignore the usual files? Make a template that you copy into all of your repos.

For many years I've have a git-ignored ".not-committed" folder in all of my repos for throwing extra anything into. It's been a huge life saver!

You can just add it in a user-level gitignore instead of ignoring it in every repo. See: ~/.config/git/ignore

Re: .gitignore Everything by Default

#68
post #66

Earlier quoted context omitted.

For many years I've have a git-ignored ".not-committed" folder in all of my repos for throwing extra anything into. It's been a huge life saver!

You can just add it in a user-level gitignore instead of ignoring it in every repo. See: ~/.config/git/ignore

I only realized very recently that being able to specify .gitignore files in any part of a repo can be combined with wildcards to just put `.gitignore` with `*` in a arbitrary directories to make them get ignored without needing to modify any wider configuration.

Re: .gitignore Everything by Default

#69
Alternative: create a .ignore folder for stuff that doesn't belong to repo at all, like your personal notes. Of course, .env shouldn't be there, because it's expected by your code, put it in .gitignore as usual. And stuff like .DS_Store should be in your global gitignore via core.excludesfile config.

There, problem solved. This covers all cases I think.

Post reply on HN