Live data from Hacker News

.gitignore Everything by Default

packagemain.tech

41–50 of 182 posts

Re: .gitignore Everything by Default

#41
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.

Re: .gitignore Everything by Default

#42
I've done something like this to understand how a unity project would interact with git + LFS as a novice to the ecosystem.

I'd incrementally add files until the project would load successfully after a fresh clone. Handling of subsequent concerns like lightmap data and external services became a lot easier having had the experience built up from zero.

Re: .gitignore Everything by Default

#43
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.

Lazygit[0] is ideal for quickly selecting files or lines you want to include in your commit. There are probably countless others. And `--patch` is also not that hard.

[0] https://github.com/jesseduffield/lazygit

Re: .gitignore Everything by Default

#44

- 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

I like https://www.toptal.com/developers/gitignore because I can mix programming language files with OS ones

Re: .gitignore Everything by Default

#45
post #14

Earlier quoted context omitted.

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.

another `git status` then `git add .` folk here, it's a quick sanity check and then quicker and frankly it's just the habit I got into when I first started using git. I've never managed to get on with any UI for basic git tasks, they always end up been slower.

I’ve been using magit lately, but I only do ‘git add .’ when it’s a very simple change. Especially in complex projects, I do some changes to isolate code or fix other issues in passing. So I stage by lines and hunks to isolate specific changes and commit them one by one. But magit is the vim of version control, so no speed issue there.

Re: .gitignore Everything by Default

#46
Just use git add -p and review your code as you place it into staged-for-commit. Your colleagues will thank you for proofreading the slop before pushing it and opening a PR. Only add files after you’ve read them one-by-one as well. git add . is lazy and shows a lack of diligence.

…is what I would say if I had no filter. But it does make sense what I see in PRs sometimes - have you proofread any of this before pushing?

Re: .gitignore Everything by Default

#47
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!

Re: .gitignore Everything by Default

#49

You should have editor specific and platform specific files in your global gitignore. https://codeberg.org/ziglang/zig/src/branch/master/.gitignor... That fixes the problem of every project enumerating the settings files for every editor. Then, as others have said, you should commit only the files you intend to commit; and ignore the files that you don’t intend to commit. This shouldn’t be difficult if you’re reviewi…

I do use this, but when I'm collaborating with others, especially a lot of people, I still duplicate it across projects. It pays to be defensive and you can't always get everyone on board with this strategy. Being defensive within your repository prevents issues before they happen.

Re: .gitignore Everything by Default

#50
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.

> The technique isn’t necessarily the right choice for every repository or developer, but is an alternative to explore.
Post reply on HN